Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Since macros return Clojure data structures, we will often
want to return lists to represent further calls, either of functions,
special forms, or other macros. Therefore, we need tools to build these
lists. It’s perfectly acceptable to use the simplest tool in our toolbox,
the list function:
(defmacro hello [name] (list 'println name)) (macroexpand '(hello "Brian")) ;= (println "Brian")
However, for more complex macros that return something more than a
simple flat list, this quickly becomes unwieldy. This is how the source
code for the standard macro while would
look, written in this manner:
(defmacro while
[test & body]
(list 'loop []
(concat (list 'when test) body)
'(recur)))
The gist of this macro is lost in all the calls to list and concat.