Syntax Quoting
A lot of the art of writing macros lies in mastering the separation between expansion code and output code. A lot of the control over that separation depends on deciding what gets quoted when the macro is expanded and what does not get quoted. The previous example started to reveal the limits of the standard quote
special form. Once a list has been quoted, all its symbols and sub-lists are quote
d as well. As such, quote
is a fairly heavy-handed tool.
For this reason, Clojure, like many Lisps, provides a more sophisticated quoting mechanism called syntax quoting. Syntax quoting uses '
, the backtick character, instead of the standard single quote. When used by itself, the backtick has more or less the same behavior as quote
: all symbols and sub-lists are quoted by default. The difference is that syntax quoting allows us to mark certain forms, sub-lists, or symbols that should not be quoted.
With syntax quoting, we can simplify our macro from the previous section...