Browse Clojure Foundations for Java Developers

Understanding Macro Expansion

Use macroexpand to debug macros by inspecting the code they generate.

Macros are easiest to understand when you stop guessing and start expanding.

At the REPL, two tools do most of the work:

  • macroexpand-1 expands a form once (one macro step).
  • macroexpand keeps expanding until the form is no longer a macro call.
1(macroexpand-1 '(when true (println "hi")))

As a Java developer, treat this like looking at generated source: you don’t trust the generator until you can read what it produces.

In this section

Revised on Friday, April 24, 2026