Macro Hygiene
Like most programming languages, Clojure provides a lot of resources for avoiding name collisions. Namespaces, let
bindings, and lexical scope, all help to make it fairly difficult to override variables by choosing the wrong name. Because they operate in a different space, and at a different time, macros have the potential to go around some of those guardrails. Macro hygiene is the art of writing macros that avoid variable capture. Variable capture is what happens when a symbol produced by a macro coincides with a macro in the surrounding environment.
Note
The term variable capture has its origins in other languages of the Lisp family. Unlike Clojure, most Lisps do not have immutable data structures, so the word "variable" is perfectly appropriate. We'll continue to say "variable capture," even though most Clojure "variables" aren't really variables.
Here's a quick example. Earlier in this chapter, we tried to write...