Chapter 8. Macros

 

If you give someone Fortran, he has Fortran. If you give someone Lisp, he has any language he pleases.

Guy Steele

This chapter covers

Macros are where the rubber of “code is data” meets the road of making programs simpler and cleaner. To fully understand macros, you need to understand the different times of Clojure, of which macros perform the bulk of their work at compile time. We’ll start by looking at what it means for code to be data and data to be used as code. This is the background you’ll need to understand that control structures in Clojure are built out of macros, and how you can build your own. The mechanics of macros are relatively simple, and before you’re halfway through this chapter you’ll have learned all you technically need to write your own. Where macros get complicated is when you try to bring theoretical knowledge of them into the real world, so to help you combat that we’ll lead you on a tour of practical applications of macros.

8.1. Data is code is data

8.2. Defining control structures

8.3. Macros combining forms

8.4. Using macros to change forms

8.5. Using macros to control symbolic resolution time

8.6. Using macros to manage resources

8.7. Putting it all together: macros returning functions

8.8. Summary

sitemap