Browse Clojure Foundations for Java Developers

Macros and Metaprogramming

Learn when macros help and how to write them without making code unreadable.

Macros are one of Clojure’s superpowers—and one of its easiest footguns. This chapter teaches what macros actually are (code that writes code), how to reason about expansion, and how to decide when a macro is justified.

For Java developers, a good analogy is “compile-time transformation,” but with much more direct access to syntax. The important discipline is to keep macros small, predictable, and boring: most problems are still better solved with functions and data.

If you take one habit away, let it be this: reach for macroexpand early and often, and always read the expanded code as if you were reviewing it in a pull request.

In this section

Revised on Friday, April 24, 2026