Making Macros Simpler
The unless macro is a great simple example, but most macros are more complex. In this section, we’ll build a set of increasingly complex macros, introducing Clojure features as we go. For your reference, the following table summarizes the features introduced.
Form | Description |
|---|---|
foo# | Auto-gensym: Inside a syntax-quoted section, create a unique name prefixed with foo. |
(gensym prefix?) | Create a unique name, with optional prefix. |
(macroexpand form) | Expand form with macroexpand-1 repeatedly until the returned form is no longer a macro. |
(macroexpand-1 form) | Show how Clojure will expand form. |
(list-frag? ~@form list-frag?) | Splicing unquote: Use inside a syntax quote to splice an unquoted list into a template. |
‘form | Syntax quote: Quote form, ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access