Chapter 11. More macros and DSLs
This chapter covers
- Anaphoric macros
- Shifting computation to compile time
- Macro-generating macros
- Designing, writing, and optimizing domain-specific languages in Clojure
This final chapter is about what many consider the most powerful feature of Clojure. John McCarthy, the inventor of the Lisp programming language, once said that Lisp is a local maximum in the space of programming languages.[1] Clojure macros make it possible to do arbitrary code transformations of Clojure code, using Clojure itself. No programming language outside the Lisp family can do this in such a simple way. This is possible because code is data.
1History of Lisp (paper presented at the first History of Programming Languages conference, June 1–3, 1978), http://www-formal.stanford.edu/jmc/history/lisp/lisp.html.
You’ve seen a lot of macros in the course of this book, including in chapter 7, which served as an introduction to the topic. In this section, you’re going to see a lot more but with two new points of focus: the advanced uses of macros and the conscious design of a simple domain-specific language. Mastering these topics will let you design elegant abstractions for even the most demanding of problem domains.