[racket] Again on bindings visibility in eval

From: Stephan Houben (stephanh at planet.nl)
Date: Fri Jul 15 09:56:32 EDT 2011

On 07/15/2011 02:07 PM, Thomas Chust wrote:

> yes, Clojure's mitigation strategy for avoiding hygiene problems has two
> components: The #-suffix syntax that acts as a clever shorthand for
> gensym and the `-quote syntax that employs reader magic to prefix every
> symbol read inside the syntax-quoted expression with a namespace.
> Gensym allows you to reliably avoid the problem that macro introduced
> identifiers might inadvertently shadow user defined identifiers.

Unfortunately Clojure's gensym is not a "real" gensym in the usual
Lisp sense, rather it is like Common Lisp's "gentemp":

user=> (eval `(def ~(gensym) 42))
user=> user/G__12

i.e. the symbol is interned.

"gentemp" is widely considered a bad idea, even by the CL authors:

In particular:
"Just because gentemp creates a symbol which did not previously exist does not mean that such a symbol might not be seen in the future (e.g., in a data file---perhaps even 
created by the same program in another session). As such, this symbol is not truly unique in the same sense as a gensym would be. In particular, programs which do automatic 
code generation should be careful not to attach global attributes to such generated symbols (e.g., special declarations) and then write them into a file because such global 
attributes might, in a different session, end up applying to other symbols that were automatically generated on another day for some other purpose.

See also:

Too bad Clojure revived this spectre from the past.
And apparently there is no way to do a "real" (uninterned) gensym.

BTW, I was wrong to say that quasiquote is undocumented, they just renamed it syntax-quote.


Posted on the users mailing list.