Accessing a local from one macro in another executed in the scope of the let
Be gentle, as my macrofoo is weak.
What I'd like to do is something like this:
(defmacro foo [x] `(dosync (alter x# conj x)))
(defmacro bar [] `(let [x# (ref [])] (foo 3)))
Is this possible? I can't just (let [x ..] ..)
because of symbol capturing.
NOTE: I'm aware this example is开发者_JAVA百科 trivial and not macro-worthy, but it's the simplest example I could come up with.
I needed to force symbol capturing.
(defmacro foo [x] `(dosync (alter ~'x conj x)))
(defmacro bar [] `(let [~'x (ref [])] (foo 3)))
Although dangerous if you don't understand macros thoroughly, this works.
精彩评论