On Mon, May 17, 2004 at 06:35:59AM +0900, rolo wrote:
> Florian Gross wrote:
> 
> I heavily assume that it's part of the language specification, because
> we have this syntax:
> 
> obj = "foo"
> class << obj
>    # everything in here is executed in the context of the singleton class
>    def reverse; "bogus"; end
> end
> obj.reverse # => "bogus"
> 
> ->
> yes, but this does not mean we have singleton classes as such. This only
> means that message reverse belongs obj. The inherent assumption is that
> message processing is part of class and not object. Hence singleton class.
> If the Objects themselves can process message we do not need an explicit
> singleton class. This syntax shall remain even if there is no singleton
> class.

It also corresponds more naturally to the following:

singleton = class << obj; self end

If there were no "real" singleton classes, you'd have to add a 'virtual
singleton' that would operate on the m_tbl of the object. Also keep in
mind that the proxy classes corresponding to singleton classes are added
lazily, i.e. there's no additional cost for an object w/o singleton
methods. That would not be the case w/ the alternate implementation
you mention.

It hence has conceptual advantages (maps more naturally to Ruby's
semantics) and obvious implementation pros. There's no point in breaking
deliberately the 'klass chain' model if it's less clear and more costly
(at least when considering the rest of the current runtime).

-- 
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

'Mounten' wird f drei Dinge benutzt: 'Aufsitzen' auf Pferde, 'einklinken'
von Festplatten in Dateisysteme, und, nun, 'besteigen' beim Sex.
	-- Christa Keil