Chapter 7. Evolving Clojure through macros
This chapter covers
- A deep dive into macros
- Macro examples from within Clojure
- Writing your own macros
Macros are the most distinguishing feature of Clojure when compared to languages such as Java and Ruby. Macros make possible things that can only be dreamed of in other languages. The macro system is why Lisp is known as the programmable programming language, and this chapter will show you how you can grow your own language on top of Clojure. Macros are a useful ingredient in bottom-up programming, the approach where an application is written by first modeling low-level entities in a domain and then combining them to create complex ones. Understanding and using macros well is the key to becoming a master Clojure programmer.
If you talk to seasoned Lisp or Clojure programmers, you’ll find that opinion about the use of macros varies a great deal. Some say that macros are almost too powerful and that they should be used with great caution. I’ve always thought that any feature of a programming language can be misused when it isn’t fully understood. Further, the advantages of using macros far outweigh the perceived disadvantages. After all, the whole point of Clojure being homoiconic is to make the macro system possible.