From: Chad Perrin Date: 2007-03-09T08:04:54+09:00 Subject: Re: Paul Graham explains Ruby symbols On Fri, Mar 09, 2007 at 06:11:43AM +0900, Rick DeNatale wrote: > On 3/8/07, Chad Perrin wrote: > >On Thu, Mar 08, 2007 at 02:17:13AM +0900, Rick DeNatale wrote: > >> On 3/6/07, Luciano Ramalho wrote: > >> >Paul Graham offers this excellent explanation for the symbol type: > >> > > >> >"Symbols are effectively pointers to strings stored in a hash table. > >> >So you can test equality by comparing a pointer, instead of comparing > >> >each character." [1] > >> > > >> >Of course, he's talking about symbols in Lisp, but what he says > >> >applies equally well to Ruby and Smalltalk. > >> > >> I find this a little too implementation-centric a description. > > > >Unfortunately, there's no way to differentiate a string literal from a > >symbol in a definitive manner without brushing up against > >implementation. At least, I haven't seen such a thing yet. > > lets see > > def is_symbol?(arg) > arg.object_id == arg.to_sym.object_id rescue false > end . . . which brushes up against implementation. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] "The first rule of magic is simple. Don't waste your time waving your hands and hopping when a rock or a club will do." - McCloctnick the Lucid