From: Brian Candler Date: 2007-05-16T02:39:41+09:00 Subject: Re: Why was the "Symbol is a String"-idea dropped? On Wed, May 16, 2007 at 12:23:09AM +0900, Gary Wright wrote: > > On May 15, 2007, at 10:53 AM, Brian Candler wrote: > > >On Tue, May 15, 2007 at 10:54:05PM +0900, Robert Dober wrote: > >>On 5/15/07, Brian Candler wrote: > >> > >>>But then what you want are not symbols, but true immutable > >>>strings. By that > >>>I mean: some object where I can write 10MB of binary dump. If I > >>>want to add > >>>one character to the end of it, then I create another object > >>>containing > >>>10MB+1byte of binary dump, and the old 10MB object is garbage- > >>>collected. > >>But of course we have immutable strings already :))) > >> > >>class IString < String > >> def initialize str > >> super(str) > >> freeze > >> end > >>end > > > >Yes, but it's not a singleton. > > > You've stated or implied a couple of times in this discussion that > symbols are 'singletons', but I thought the conventional definition > of 'singleton' was of a class with only a single instance, where the > instance is called a singleton. That doesn't describe Ruby's symbols. > > I think what you are getting at is the idea that identity and > equality are one and the same for symbols. No, that's not exactly what I meant, but sorry for not being more precise. What I meant was: there is only ever one symbol object in existence for a particular sequence of characters. :foo.object_id in one part of the program is always the same as :foo.object_id elsewhere. If it were Symbol.new("foo") always returning the same object then I guess it would probably be called the multiton pattern. Regards, Brian.