我一直在努力寻找答案或制定解决方案.我试图找出如何在Clojure中创建代码的代码.对于我的第一个专长,我想要一个函数,它将打印到stdout符号的名称及其值,对调试很有用.例:
(def mysymbol 5)
(debugging-function mysymbol)
mysymbol: 5
Run Code Online (Sandbox Code Playgroud)
那有意义吗?谢谢你的帮助.
发布讨论更新
以下是@amalloy的答案:
(defmacro ?
"A useful debugging tool when you can't figure out what's going on:
wrap a form with ?, and the form will be printed alongside
its result. The result will still be passed along."
[val]
`(let [x# ~val]
(prn '~val '~'is x#)
x#))
Run Code Online (Sandbox Code Playgroud)
所以:
(? myvariable)