May 2018
Beginner to intermediate
290 pages
6h 43m
English
If it seems like macros might be one of those advanced programming features, something that you aren’t likely to have a lot of contact with until you get really good at the language, well, no. Certainly, you can—and probably should—do a lot of Clojure programming without writing any macros. But there’s no avoiding macros because much of the familiar core of Clojure is actually made of macros.
Here, for example, is a somewhat cut-down version of Clojure’s own when:[34]
| | (defmacro when |
| | [test & body] |
| | (list 'if test (cons 'do body))) |
And here’s the rather more complicated cond:
| | (defmacro cond |
| | [& clauses] |
| | (when clauses |
| | (list 'if (first clauses) |
| | (if (next clauses) |
| | (second clauses) |
| | (throw (IllegalArgumentException. ... |
Read now
Unlock full access