O'Reilly logo

Mastering Clojure Macros by Colin Jones

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Evaluating (or Not) in Time and Place

One of the least complex (but most-used) macros in Clojure is comment, which entirely avoids evaluating the code contained in it:

context/comment.clj
 
(​defmacro​ ​comment
 
"Ignores body, yields nil"
 
{:added ​"1.0"​}
 
[& body])
 
 
(​comment
 
(​println​ ​"wow"​)
 
(​println​ ​"this macro is incredible"​))
 
;=> nil
 
 
(​+​ 1 2) ​; this is another type of comment
 
(​+​ 1 2) #_(​println​ ​"this is yet another"​)

There are a couple of other commenting mechanisms in Clojure, but comment is the only one that’s a macro (the others are built into the Clojure reader). The return value of comment is always nil, and none of the code passed to it is ever evaluated. Since it’s a macro, the code passed in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required