3 ms·
To completely solve the hygiene problem on an academic level, you have to use gensyms for all references generated by the macro, including all function symbols.
by kazinator 10y ago
To completely solve the hygiene problem on an academic level, you have to use gensyms for all references generated by the macro, including all function symbols.
Lisp macros don't bother doing this because the Lisp-2 separation provides adequate hygiene. Programs which choose to lexically shadow standard functions like cons or list in the function namespace are considered to be sticking a fork in the proverbial toaster, and so that is not handled.
That would't work as well in Scheme because the mere presence of a variable called list in the user's code would interefere with a (list ...) function call generated by a macro.
Also providing hygiene are packages. If macro-generated code references private symbols in the macro's own package, everything is cool. Packages take care of the problem for nonstandard functions. You just don't use another package's symbols for local functions and variables, and that's that.