Clojure macros and character binding

not sure how to express it.

I wrote a macro that takes two arguments. The first essentially contains identifiers for generating the let expression. The second is the code to use inside the let expression (it wants to have access to these identifiers).

Example:

(match (Add {ast-> x}) (println x))

When the second argument is raw code, everything works well. x binds to x defined in the let expression (when macroexpanded, it just displays as x). However, when the second argument is the macro that generates (println x), x expands to something like user / x.

Any good ideas on how to fix this?

+3
source share
1 answer

, :

(defmacro foo
  []
  `(println x))

, x . :

(defmacro foo
  []
  `(println ~'x))

x println x, .

+6

Source: https://habr.com/ru/post/1772267/


All Articles