Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

7.1. Macro basics

In order to explain what a macro is, we’ll take a step back and examine language runtimes again. Recall from chapter 1 that the Clojure runtime processes source code differently when compared to most other languages. Specifically, there’s a read phase followed by an evaluation phase. In the first phase, the Clojure reader converts a stream of characters (the source code) into Clojure data structures. These data structures are then evaluated to execute the program. The trick that makes macros possible is that Clojure offers a hook between the two phases, allowing the programmer to process the data structures representing the code before they’re evaluated. Figure 7.1, which you also saw in chapter 1, illustrates these phases.

Figure 7.1. Phases of the Clojure runtime. This separation is what makes the macro system possible.



  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint