What is a Macro?
A macro is a piece of code that is executed before your code is compiled. The code contained inside a macro call is transformed into something different and then passed on to the compiler. In Clojure, macros are defined by calling defmacro
. A call to defmacro
looks fairly similar to a call to defn
:
(defmacro my-macro   "Macro for showing how to write macros"   [param]   ;;TODO: do something   )
Despite this apparent similarity, there is a huge difference between macros and functions. Unlike functions, macros are not called at runtime. When your program finally starts running, the macros have already been called. The code they produce has already been included in your program as if you had typed it in yourself:
Keep this idea in mind while you think about and work with macros: any macro in your code could...