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, ...

Get Programming Clojure, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.