As previously described in this chapter, it's trivial to read and evaluate code in Clojure using the
eval functions and their variants. Instead of evaluating code right after it is parsed, we can use macros to first transform code programmatically using quoting and unquoting, and then evaluate it. Thus, macros help us define our own constructs that rewrite and transform expressions passed to them. In this section, we will explore the basics of creating and using macros.
Macros need to be expanded when they are called. All Clojure code is read, macroexpanded, and evaluated by the reader as we described earlier. Let's now take a look at how macroexpansion is performed. As you may have guessed already, this ...