When to Use Macros
In 1996, author Chuck Palahniuk released the novel “Fight Club”, which was later made into a movie. The so-called fight club in the story had a set of rules. The first rule of fight club was, "You don’t talk about fight club."
In a similar spirit, we introduce Macro Club. Macro Club has two rules, plus one exception. The first rule of Macro Club is Don’t Write Macros. Macros are complex, and they require you to think carefully about the interplay of macro expansion time and compile time. If you can write it as a function, think twice before using a macro.
The second rule of Macro Club is Write Macros If That Is the Only Way to Encapsulate a Pattern. All programming languages provide some way to encapsulate patterns, but ...
Get Programming Clojure, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.