我在学习的Clojure宏的过程中,我越来越想在这个宏中使用macroexpand-1,当一个NullPointerException异常:为什么在这个Clojure宏上执行macroexpand-1时会出现NullPointerException异常?
(def config {:ns 'bulbs.neo4jserver.client,
:root-uri "http://localhost:7474/db/data/"})
(def data {:name "James"})
(defmacro create
[config data]
`(~(ns-resolve (:ns config) 'create-vertex) config data))
(macroexpand-1 '(create config data))
试图编译这个返回:
Unknown location:
error: java.lang.NullPointerException
Compilation failed.
但评估宏的身体......
`(~(ns-resolve (:ns config) 'create-vertex) config data)
...返回此...
(#'bulbs.neo4jserver.client/create-vertex bulbs.vertices/config bulbs.vertices/data)
......这是我想我想要的。
更新:如果我手动更换(:ns config)
与'bulbs.neo4jserver.client
然后错误消失 - 你如何使(:ns config)
发挥不错?
啊。谢谢蒂姆。 – espeed