From: "David A. Black" Date: 2009-01-31T21:12:35+09:00 Subject: Re: global generator of unique symbols On Sat, 31 Jan 2009, Pascal J. Bourguignon wrote: > Thomas Hafner writes: > >> Hello, >> >> is there a global generator of unique symbols? See article >> why that can be needed. There I >> have defined myself a generator, but that's no real solution: if >> software is going to be put together from different libraries, only >> one common generator should be used by all software parts to prevent >> symbol clash. >> >> With ``generator of unique symbols'' I mean: the first time since >> program start it will generate any symbol. Any other time it will >> generate a symbol that differs from all already generated symbols. >> >> Regards >> Thomas > > > (@@gensym_counter = 0) > > (def gensym(base = "com_informatimago_ruby_g") > (@@gensym_counter = (@@gensym_counter + 1)) > ((base + (@@gensym_counter . to_s)) . to_sym) > end) > > (gensym) > --> :com_informatimago_ruby_g5 I still don't get the fake Lisp thing. Why write cryptic, unidiomatic, turgid Ruby code, when Ruby provides a clean, clear syntax? It's not about understanding Ruby's precedence rules; I'm sure you know what x += 1 means, and don't really need to write (x = (x + 1)) in order to understand it, and likewise that you can figure out how to write: (base + x.to_s).to_sym without the added clutter. I have an obscure feeling that you're trying to send us a message about Lisp being more serious, and Ruby only being worthwhile when it's made to look superficially like Lisp. But is that really doing justice to either language? Is the chief lesson of studying Lisp really that you should slap parentheses on as many expressions as possible in other languages? It doesn't make sense to me. David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) http://www.wishsight.com => Independent, social wishlist management!