3 ms·
> as soon as you add guardrails like hygiene (like Scheme does), the inherent conceptual simplicity of Common Lisp style macros is greatly reduced Clojure offe
by koito17 2y ago
> as soon as you add guardrails like hygiene (like Scheme does), the inherent conceptual simplicity of Common Lisp style macros is greatly reduced
Clojure offers a nice middle-ground to this. In Clojure, symbols are namespaced, and syntax quote "fully qualifies" symbols. A "fully qualified" symbol is a symbol with its namespace explicitly written out. For instance, foo is unqualified whereas clj.user/foo is fully qualified. The language disallows binding fully qualified symbols. So the most common bugs arising in unhygienic macros are eliminated while maintaining the same level of "simplicity" as macros in Common Lisp.
There are also other features to help ensure hygiene, such as syntax that automatically produces gensyms for you. e.g. instead of
(let [foo-sym (gensym)]
`(let [~foo-sym some-value]
(do something with ~foo-sym))))
one can simply write
`(let [foo# some-value]
(do something with foo#))