clojure中的宏扩展问题

clojure中的宏扩展问题,clojure,Clojure,我有一个clojure宏: (defmacro show [x] `(show-fn ~x) ) :其中给出: (show hello) 我决心: (show-fn 'hello) :我该怎么做 user=> (defmacro show [x] `(~'show-fn '~x)) #'user/show user=> (macroexpand '(show hello)) (show-fn (quote hello)) 这称为“符号捕获”。它防止在当前名称空间中解析符号

我有一个clojure宏:

(defmacro show
  [x] `(show-fn ~x)
)
:其中给出:

(show hello)
我决心:

(show-fn 'hello)
:我该怎么做

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

这称为“符号捕获”。它防止在当前名称空间中解析符号,就像您的示例一样。

@Zubair Done。请注意,它实际上不会扩展为“hello,因为”扩展为“quote”。但这是一样的。你可能不想捕捉
show fn
——通常最好是用语法引用,比如
(show fn'~x)
。他这样做是出于某种原因。不确定你是在回应他还是我。我只是回答这个问题,而不是就为什么不做这件事做讲座。