开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜