我正在编写一个宏来实现when内置宏,这里是代码:
(defmacro when-valid
"Macro that does a series of actions if the condition
is true"
[condition & actions]
`(if ~condition (~cons 'do ~actions) nil))
Run Code Online (Sandbox Code Playgroud)
但当我评估它时:
(when-valid (< 1 2) (println "hello") (println "dear"))
Run Code Online (Sandbox Code Playgroud)
我得到输出:
hello
dear
clojure-noob.core=> NullPointerException
clojure-noob.core/eval17411
Run Code Online (Sandbox Code Playgroud)
我应该nil而不是NullPointerException.有谁知道我做错了什么?
谢谢.
clojure ×1