Hello-Macro in Clojure
If define the unless as function like this,
(defn unless [expr form] (if expr nil form))
Does that work?
(unless false (println "this should print")) => this should print (unless true (println "this should not print")) => this should not print
Obviously the answer is no.
The reason is Clojure evaluates all the arguments before passing them to
a function, so the println
is called before unless ever sees it.
So it seems Clojure is applicative order evaluation, but not normal
order evaluation. (SICP exe. 1.5)
Therefore Macro.
(defmacro unless [expr form] (list 'if expr nil form))