Making Macros Simpler
The unless macro is a great simple example, but most macros are more complex. In this section, we will build a set of increasingly complex macros, introducing Clojure features as we go. For your reference, the features introduced in this section are summarized in the following table.
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 ... |
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