Learn the small set of macro-writing tools Java engineers need first: defmacro, syntax quote, unquote, unquote-splicing, auto-gensyms, and expansion review.
The safest way to write a macro is to start with a function and move to defmacro only when you need syntax or evaluation control.
Basic macro writing is mostly about three habits:
| Habit | Why it matters |
|---|---|
| Build a tiny expansion first. | The generated code should be boring and reviewable. |
| Use syntax quote, unquote, and splicing deliberately. | These decide which parts are templates and which parts come from the caller. |
Check macroexpand-1 before adding features. |
Expansion review catches multiple evaluation, name capture, and hidden control flow. |
For Java engineers, treat a macro like source generation inside the language. The call site may be compact, but the expansion is the real code your team must understand.