On Sun, Nov 8, 2009 at 5:56 PM, Kevin Tucker <tuckerke...@gmail.com> wrote:

> This is something that I have been wondering about too.  In CL the
> symbols gensym produces can not be read by the reader so there can be
> no collision cause the only way to get a handle on the symbol is to
> create it with gensym and hold on to it.  In other words you couldn't
> construct a symbol that would = one gensym returns even after the fact
> if you wanted to except by copying the reference.  At least that was
> my understanding of it.  Seem like those semantics work pretty well.


Actually, this suggests another possibility for collision prevention:
disallow one character from appearing in symbols read by the reader or
produced by (symbol a-string). Both would throw an exception if they saw it.
It should be a character rarely if ever used in symbols; something like ~ or
' would be ideal. Gensyms could then include this character and be assured
of never colliding with non-gensyms. (This would include the auto-generated
parameter names produced by the #(foo %1 bar %2) reader macro, as well as
those produced in `(foo x# ~bar) and by (gensym).)

There's still a problem with macroexpand output, but instead of run-time
behavior changes the output just wouldn't compile. The illegal character
might also be stripped from symbols in macroexpand output, to make output
that will compile and should have the intended semantics but will have the
original slight chance of a collision of names.

Making the gensym symbol names begin with a leading ' gets you halfway
already since no such symbol name can be generated by the reader already;
the ' will be treated as (quote ...). It also won't throw an exception,
though, but it will be clear why it doesn't work to anyone who knows about
quoting. Having the symbol function reject strings that start with ' would
then be the only other needed change, and is extremely unlikely to break any
existing code.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to