~andreyorst

Moscow

https://andreyorst.gitlab.io/

I love Lisp and text editors!


#103 Improve relative require 17 days ago

Comment by ~andreyorst on ~technomancy/fennel

The technique from the above comment is now part of cljlib. I will monitor if it breaks.

#103 Improve relative require a month ago

Comment by ~andreyorst on ~technomancy/fennel

Had to update the macro above because it stopped working:

(macro rel-require [module macro?]
  `(if (: (or ... "") :match "(.+%.)[^.]+")
       (require (.. (: (or ... "") :match "(.+%.)[^.]+") ,module))
       (= ... ,(if macro? "init-macros" "init"))
       (require ,module)
       (require (.. ... "." ,module))))

Without this change it is compiled to IIFE, and not static.

#128 comment forms that contain ]] break when compiled a month ago

Ticket created by ~andreyorst on ~technomancy/fennel

The following code:

(comment
 (let [[a b] [1 2]]
   (+ a b)))

When compiled produces Lua code that is not syntactically valid:

--[[ (let [[a b] [1 2]] (+ a b)) ]]
return nil

I believe comment should check if its body contains the delimiter, and use [=[ syntax ]=] instead.

This even breaks with strings:

-- (comment "]]")
--[[ "]]" ]]
return nil

#127 comment breaks code when used with --correlate a month ago

Comment by ~andreyorst on ~technomancy/fennel

I've sent the patch, but the pipeline seems to be broken with something unrelated

#127 comment breaks code when used with --correlate a month ago

Ticket created by ~andreyorst on ~technomancy/fennel

This code will not work after compilation with the --correlate flag

(comment "foo") (local x 10)
(print x)

Without --correlate the code works because local is put on its own line, but with correlate the following happens:

--[[ "foo" ]]-- local x = 10
return print(x)

local x = 10 is a part of the comment, because multiline comments in Lua end with just ]] not with ]]--

In other words, it's similar to ending C comments like this /* foo *///

#125 nils in quoted lists affect macros imported via import macros but not inline macros a month ago

Ticket created by ~andreyorst on ~technomancy/fennel

I've updated Fennel, and one of my projects broke in a very bizarre way. Some functions become empty. After a bit of bisecting, and debugging, I've found that this commit is where it breaks: d064522bac302c967947c7f648b4468ceb493895

Here's the minimal macro defn which re-arranges docstring and argument list (this was the reason why my project wasn't compiling properly):

(fn defn [name doc? args ...]
  (let [doc (if (= :string (type doc?)) doc?)
        args* (if doc args doc?)
        body (if doc `(do ,...) `(do ,args ,...))]
    `(local ,name (fn ,name ,args* ,doc ,body))))

{: defn}

Here, when I import it, the first function foo compiles as an empty function, and the bar function compiles correctly:

(import-macros {: defn} :m)

(defn foo [bar]                         ; compiles to empty function
  bar)

;; local foo
;; local function foo0(...)
;; end
;; foo = foo0

(defn bar "doc" [baz]                   ; works
  baz)

;; local bar
;; local function bar0(...)
;;   return baz
;; end
;; bar = bar0

However, macrodebugging these definitions in the REPL shows that the code generated is correct:

>> (macrodebug (defn foo [bar] bar))
(local foo (fn foo [bar] nil (do bar)))

>> (macrodebug (defn bar "doc" [baz] baz))
(local bar (fn bar [baz] "doc" (do baz)))

And even more interestingly, if I use macro instead of importing the defn macro, it compiles just fine:

;; (import-macros {: defn} :m)

(macro defn [name doc? args ...]
  (let [doc (if (= :string (type doc?)) doc?)
        args* (if doc args doc?)
        body (if doc `(do ,...) `(do ,args ,...))]
    `(local ,name (fn ,name ,args* ,doc ,body))))

(defn foo [bar]
  bar)

;; local foo
;; local function foo0(bar)
;;   return bar
;; end
;; foo = foo0
;; 

(defn bar "doc" [baz]
  baz)

;; local bar
;; local function bar0(baz)
;;   return baz
;; end
;; bar = bar0

These macros are exactly the same, the only difference is how they're brought into the scope.

#122 empty list in values binding generates bad code a month ago

Ticket created by ~andreyorst on ~technomancy/fennel

(local () (values))
Bad code generated - likely a bug with the compiler:
--- Generated Lua Start ---
local  = nil
local ___i___ = 1
while true do
 local name, value = debug.getlocal(1, ___i___)
 if(name and name ~= "___i___") then
 ___replLocals___[name] = value
 ___i___ = ___i___ + 1
 else break end end
return nil--- Generated Lua End ---

Also happens with other binding forms.

#119 calling error in fennel.repl readChunk doesn't trigger :onError properly 3 months ago

Comment by ~andreyorst on ~technomancy/fennel

the fix works, thanks!

#119 calling error in fennel.repl readChunk doesn't trigger :onError properly 3 months ago

Ticket created by ~andreyorst on ~technomancy/fennel

Noticed that the following code produces a lot of Parse error: nil messages.

(local fennel (require :fennel))
(fennel.repl {:readChunk #(error "oh no!")})

I suppose the nil there should have been oh no!.

#103 Improve relative require 4 months ago

Comment by ~andreyorst on ~technomancy/fennel

From https://github.com/bakpakin/Fennel/pull/423:

(macro rel-path [module from-macro?]
  `(.. (or (: (or ... "") :match "(.+%.)[^.]+")
           (if (= ... ,(if from-macro? "init-macros" "init"))
               ""
               (.. ... ".")))
       ,module))

This macro should cover most common cases for relative require from regular modules and macro modules.