【发布时间】:2011-03-28 16:36:55
【问题描述】:
在compojure library in the core namespace,我看到如下表格:
(defn- compile-route
"Compile a route in the form (method path & body) into a function."
[method route bindings body]
`(#'if-method ~method
(#'if-route ~(prepare-route route)
(fn [request#]
(let-request [~bindings request#]
(render (do ~@body) request#))))))
和
(defmacro GET "Generate a GET route."
[path args & body]
(compile-route :get path args body))
在文件的更上方,if-method 和 if-route 函数使用 defn-s 定义。
我不明白 #' 在这个 compile-route 函数中的含义。 (var ...) 的文档说:
符号必须解析为 var,并返回 Var 对象本身(而不是其值)。阅读器宏 #'x 扩展为 (var x)。
但对我来说,在正在发生的事情(即从 defmacro 中调用)的上下文中,听起来这意味着将返回符号的值,这与可替换性听起来是一样的:
(def x 5)
(+ x 7)
-> 12
即(+ x 7) 扩展为(+ 5 7) 或与(+ 5 7) 相同
我在这里错过了什么?
【问题讨论】:
标签: clojure