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 ...

Get Mastering Clojure Macros now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.