Mark Sparshatt <[EMAIL PROTECTED]> writes:
>
>I'm not 100% certain about the details but I think this is how it works.
>
>In languages like C++ objects and classes are completely seperate.
>classes form an inheritance heirachy and objects are instances of a
>particular class.
>
>However in some languages (I think that Smalltalk was the first) there's
>the idea that everything is an object, including classes. So while an
>object is an instance of a class, that class is an instance of another
>class, which is called the metaclass. I don't there's anything special
>about these classes other than the fact that their instances are also
>classes.
>
>
>Thinking about it I think you may have the relationship between
>ParrotObject and ParrotClass the wrong way around. Since a class is an
>object but and object isn't a class it would be better for ParrotClass
>to inherit from ParrotObject, rather than the other way round.
>
>In Ruby when you create a class Foo, the Ruby interpreter automatically
>creates a class Foo' and sets the klass attribute of Foo to point to Foo'.
>
>This is important since class methods of Foo are actually instance
>methods of Foo'. Which means that method dispatch is the same whether
>you are calling an instance of class method.

So in perl5-ese when you call 

   Foo->method

you are actually calling sub Foo::method which is in some sense
a "method" of the %Foo:: "stash" object.

So what you suggest is as if perl5 compiled Foo->method
into (\%Foo::)->method and the %Foo:: 'stash' was blessed...


>
>foo.method()
>
>looks at foo's klass attribute then checks the returned class object
>(Foo) for method
>
>Foo.method()
>
>looks at Foo's klass attribute and again checks the returned class
>object (Foo') for method.
>
>The Pickaxe book has got a better explanation of this (at
>http://www.rubycentral.com/book/classes.html though without any diagrams
>:( )
>
>In Python when defining a class it's possible to set an attribute in the
>class that points to the classes metaclass. The metaclass itself is just
>a normal class that defines methods which override the normal behaviour
>of the class.
>
>IIRC Python has got both class methods and meta class instance methods
>which work almost (but not quite) in the same way as each other.
>
>Hopefully someone with more experience with Python will be able to
>explain better.
>
>I'm not sure if this has cleared things up or just made them more confusing.

Reply via email to