Learn what Clojure macros are, how macro expansion differs from ordinary function calls, and when Java engineers should treat generated code as reviewable source.
Macros are functions that run at macro-expansion time and return Clojure code represented as data. The generated code becomes part of the program before normal evaluation.
For Java engineers, the closest mental model is compile-time code transformation, but the source language and the transformation language are the same Clojure data structures. That makes macros powerful and dangerous in the same way code generators are powerful and dangerous.
| Habit to build | Why it matters |
|---|---|
| Prefer a function first. | Functions are easier to test, compose, and debug. |
| Expand the macro at the REPL. | The expansion is the code reviewers must understand. |
| Keep generated code boring. | Clever syntax is not worth unreadable behavior. |
| Use macros for evaluation control. | Functions cannot stop their arguments from evaluating first. |
Read this section as a safety-first introduction: understand what macros receive, what they return, and how to decide whether a macro is justified.