August 2014
Intermediate to advanced
120 pages
2h 45m
English
You’ve already seen plenty of subtleties with macros, such as the need to avoid symbol capture with gensyms, and there’s more to come. While you’re in the great position of knowing all the language’s rules for macro construction, you may still be unclear about the implications of what you know. Let’s look at a few more ways you might accidentally cause yourself grief by making the wrong assumptions about macro code.
Here’s a re-implementation of the clojure.core/and macro that seems fairly straightforward.
| beware/and_1.clj | |
| | (defmacro our-and |
| | ([] true) |
| | ([x] x) |
| | ([x & next] |
| | `(if ~x (our-and ~@next) ~x))) |
| | |
| | user=> (our-and true true) |
| | ;=> true |
| | user=> (our-and true false) |
| | ;=> false |
| | user=> (our-and ... |
Read now
Unlock full access