开发者

Problem expanding macro in clojure

I have a clojure macro:

(defmacro show
  [x] `(show-fn ~x)
)

: whi开发者_运维技巧ch given :

(show hello)

I want to resolve to :

(show-fn 'hello)

: How can I do this?


user=> (defmacro show [x] `(~'show-fn '~x))
#'user/show
user=> (macroexpand '(show hello))
(show-fn (quote hello))

This is called 'symbol capture'. It keeps the symbol from being resolved in the current namespace, as with your example.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜