May 2018
Beginner to intermediate
290 pages
6h 43m
English
One thing should be clear: macros are hard to get right—much harder than plain functions. With an ordinary function you write the code and it gets executed. With a macro you write the code that writes the code that gets executed. Implicit in this two-step process is that macros make themselves felt at two distinct times. There’s the moment when the macro is expanded—when it is writing the code—and then there’s the moment when the generated code is executed. We can see that distinction here:
| | (defmacro mark-the-times [] |
| | (println "This is code that runs when the macro is expanded.") |
| | `(println "This is the generated code.")) |
| | |
| | ;; Expand the macro and you get the 1st println |
| | ;; but not the 2nd. |
| | |
| | (defn use-the-macro ... |
Read now
Unlock full access