hygiene


Hygiene in the context of Scheme programming is automatic avoidance of variable-capture in macros. In non-hygienic macros the macro writer has to handle the possibility of inadvertant variable-capture manually (for example by generating unique names for variables with gensym?; note, however, hygiene-versus-gensym).

In simpler terms, hygiene is just proper lexical scope even in the presence of macros and modules.

An analogy can be made in C++ that CPP macros are unhygienic whereas the template system is hygienic. The C++ template system doesn't perform raw template substitution, but actually tracks the correct namespaces between the original template and the instantiation - without this it would break horribly. Common-Lisp package handling works similarly. Note this is a pretty trivial task for C++ since the template system is even lower-level than syntax-rules.

Note also that it's possible to implement a gensym work-alike with CPP macros using the non-standard __COUNTER__ macro.