Skip to content

How to nest quasiquotes? #2251

Answered by Kodiologist
glyh asked this question in Q&A
Mar 21, 2022 · 2 comments · 4 replies
Discussion options

You must be logged in to vote

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:

(defmacro inject-binaries [#* names]
  `(do
    ~@(lfor name names 
      `(defmacro ~name [#* args]
        `(hy.M.subprocess.run #(~'~(str name) ~@(map str args)))))))

(inject-binaries ls mkdir)
(ls -la)

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…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@glyh
Comment options

@Kodiologist
Comment options

@glyh
Comment options

@Kodiologist
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Kodiologist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants