What practical problem results from lack of hygienic macros in Clojure

clojurelispmacrosmeta-programmingracket

I've heard that Clojure macros are easier to write but not as reliable as Racket's hygienic macros. My question has 2 parts:

  1. How does gensym differ from hygienic macros?
  2. What do Racket macros provide that Clojure's don't? (be it safety, composability, or anything)

Best Answer

The advantage of hygienic macros is not one of language capability -- you can write macros that have good hygiene using gensym and careful quoting/unquoting at the right times. However, hygienic macros ensure your macros have good hygiene. In that respect, it's a bit like type-checking.

There may also be tooling advantages to hygienic macros. Most hygienic macro systems impose tight controls on what your macro does and how it does it (e.g., you can't execute arbitrary code when a macro defined by Scheme's syntax-case is expanded). This can make it easier to write programs that "understand" your macro and can provide additional tooling support.

On the other hand, there are some cases where unhygienic macros may be useful. For example, if you actually want to capture a binding for a specific variable (e.g., anaphoric macros) then I think you're out of luck if you only have hygienic macros.