How to nest quasiquotes? #2251
-
I'm trying to inject binaries in PATH to python's scope, here's what I got: (defmacro inject-binaries [#* names]
`(do
~@(lfor name names
`(defmacro ~name [#* args]
`(subprocess.run (+ (, (str ~~name)) ~args)))))) It's not working because if you try this: (hy.macroexpand-1
'(inject-binaries ls pwd)) You would get: (do (defmacro ls [#* args] `(subprocess.run (+ (, (str ~'ls)) ~args))) (defmacro pwd [#* args] `(subprocess.run (+ (, (str ~'pwd)) ~args)))) Which is wrong because it seems like I'm fairly new to lisps, so this may seem silly. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I think this may be a bug. But, why produce macros, anyway? Functions would have the same effect:
|
Beta Was this translation helpful? Give feedback.
-
Here's a belated but more to-the-point answer, now that I've done a deep dive into nested quasiquotation. With the new syntax for tuples (
The trick here is Bawden, A. (1999). Quasiquotation in Lisp. ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation. Retrieved from https://3e8.org/pub/scheme/doc/Quasiquotation%20in%20Lisp%20(Bawden).pdf |
Beta Was this translation helpful? Give feedback.
Here's a belated but more to-the-point answer, now that I've done a deep dive into nested quasiquotation. With the new syntax for tuples (
#( … )
instead of the old(, … )
),inject-binaries
should be written and used like this:The trick here is
~'~
, which Bawden (1999, p. 10) describes as a "cliché" of nested quasiquotation, better understood as a unit than reconstructed each time you use it.Bawden, A. (1999). Quasiquotation in Lisp. ACM SIGPLAN Workshop on Partial Evaluation and Pro…