For the context, I've been trying to write a macro that generates another macro, e.g. like this Common Lisp macro:
(defmacro maker (name id)
`(defmacro ,(intern (format nil "MAKE-~s" name)
(package-name (symbol-package name)))
(a b c)
`(list :id ,,id :a ,a :b ,b :c ,c)))
It can be used like this (maker foo 42)
which produces a macro make-foo
which in turn creates an object with baked-in ID from the parent macro, and supplied args:
* (macroexpand-1 '(maker foo 42))
(DEFMACRO MAKE-FOO (A B C) (LIST 'LIST :ID 42 :A A :B B :C C))
* (maker foo 42)
MAKE-FOO
* (make foo 3 7 11)
(:ID 42 :A 3 :B 7 :C 11)
However, when I try the same thing in Fennel, this happens:
>> (macro a [name id]
`(macro ,(sym (.. :make- (tostring name)))
[a b c]
`{:id ,,id :a ,a :b ,b :c ,c}))
unknown:5:12 Compile error: tried to use unquote outside quote
`{:id ,,id :a ,a :b ,b :c ,c}))
* Try moving the form to inside a quoted form.
* Try removing the comma.
It seems that nested quoting and multi-unquoting aren't supported, and all quoting operates on a single level. This isn't how quoting works in other lisps, such as Clojure, Racket, CL, and various Schemes.
Yeah, I agree we should support this. I'm not sure when I'll have time to look into it.