Browse Clojure Foundations for Java Developers

Common Pitfalls with Macros

Avoid multiple evaluation, variable capture, and unreadable expansions.

The most common macro bugs are not “syntax bugs.” They are semantic bugs: the macro expansion evaluates something more times than you intended, or it introduces names that collide with the caller’s code.

Watch for:

  • Multiple evaluation: if you splice an expression into two places, it runs twice.
  • Variable capture: accidentally shadowing or referencing a symbol from the caller’s scope.
  • Unreadable expansions: the generated code is harder to understand than the original boilerplate.

If you cannot explain the expansion clearly, it is usually a sign the macro is too big.

In this section

Revised on Friday, April 24, 2026