Metaclass hierarchy - Explanation - Part 1

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Metaclass hierarchy - Explanation - Part 1

Damien Cassou-3
Hi,

I would like to try explaining what is the metaclass hierarchy of
Smalltalk. This is always something new smalltalkers have problem with.
It would be interesting if an experienced smalltalker read this mail and
correct it when I'm wrong.


To understand this, you have to know the following three rules by heart:

1) In Smalltalk, everything is an object
2) In Smalltalk, each object is an instance of a class
3) In Smalltalk, each class has a superclass but one called Object


(in squeak, Object has a superclass called ProtoObject and this class
has no superclass).


Lets start with the string:


'my string'


rule 1) tells us that this is an object.
rule 2) tells us that this is an instance of a class. Here the class is:


String


rule 1) tells us that String is an object.
rule 2) tells us that String is an instance of a class. The class is:


String class


rule 1) tells us that 'String class' is an object.
rule 2) tells us that 'String class' is an instance of a class. The
class is:


Metaclass


rule 1) tells us that Metaclass is an object.
rule 2) tells us that Metaclass is an instance of a class. The class is:


Metaclass class


rule 1) tells us that 'Metaclass class' is an object.
rule 2) tells us that 'Metaclass class' is an instance of a class. The
class is:


Metaclass


Ok, we have a loop here so the rules are always verified. Cool !
Explanation:


- An object is an instance of a class
- A class is the only instance of its metaclass: String is the only
instance of the metaclass 'String class'.
- Each metaclass is an instance of the class Metaclass.


Hope this is clear. If not, please ask.
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Metaclass hierarchy - Explanation - Part 1

Michael Haupt-3
Hi Damien,

it's funny; I've used roughly the same way to explain this in a
lecture once. :-)

I have attached the one PowerPoint slide I used at the time to this
e-mail (hopefully, it gets through to the list) - there are some
animations on the slide; they should be triggered when there's a
[tick] in the slide notes.

Just a little addition to your explanation. :-)

Best,

Michael

MetaLevelSlide.ppt (60K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Metaclass hierarchy - Explanation - Part 1

Klaus D. Witzel
In reply to this post by Damien Cassou-3
On Wed, 30 Aug 2006 16:58:54 +0200, Damien Cassou wrote:

> Hope this is clear. If not, please ask.

Okay, question: have you done an inspectIt an all the expressions in your  
posting.

For example, when I do an inspectIt on the expression (String class), I  
get an instance of Metaclass. In your description, you get an instance of  
Metaclass for (String class class)

> String class
> rule 1) tells us that 'String class' is an object.
> rule 2) tells us that 'String class' is an instance of a class. The
> class is:
> Metaclass

/Klaus

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re: Metaclass hierarchy - Explanation - Part 1

Damien Cassou-3
Klaus D. Witzel wrote:
> On Wed, 30 Aug 2006 16:58:54 +0200, Damien Cassou wrote:
>
>> Hope this is clear. If not, please ask.
 >> String class
 >> rule 1) tells us that 'String class' is an object.
 >> rule 2) tells us that 'String class' is an instance of a class. The
 >> class is:
 >> Metaclass
>
> Okay, question: have you done an inspectIt an all the expressions in
> your posting.
>
> For example, when I do an inspectIt on the expression (String class), I
> get an instance of Metaclass. In your description, you get an instance
> of Metaclass for (String class class)

I don't understand you.

(String class) is an instance of Metaclass
(String class class) is Metaclass


inspecting an object shows its class as a title.

Can you rephrase please so that I understand.


I might be wrong :-)


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Metaclass hierarchy - Explanation - Part 1

Mathieu SUEN
In reply to this post by Damien Cassou-3
Damien Cassou a écrit :

> Hi,
>
> I would like to try explaining what is the metaclass hierarchy of
> Smalltalk. This is always something new smalltalkers have problem with.
> It would be interesting if an experienced smalltalker read this mail and
> correct it when I'm wrong.
>
>
> To understand this, you have to know the following three rules by heart:
>
> 1) In Smalltalk, everything is an object
> 2) In Smalltalk, each object is an instance of a class
> 3) In Smalltalk, each class has a superclass but one called Object
>

You can use this link:
http://www.iam.unibe.ch/~ducasse/Teaching/CoursAnnecy/0506-M1-COO/07Metaclasses.pdf

I like the scheme, it help a lote to understand.

Math
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re: Metaclass hierarchy - Explanation - Part 1

Klaus D. Witzel
In reply to this post by Damien Cassou-3
On Wed, 30 Aug 2006 17:50:41 +0200, Damien Cassou wrote:

> Klaus D. Witzel wrote:
>> On Wed, 30 Aug 2006 16:58:54 +0200, Damien Cassou wrote:
>>
>>> Hope this is clear. If not, please ask.
>  >> String class
>  >> rule 1) tells us that 'String class' is an object.
>  >> rule 2) tells us that 'String class' is an instance of a class. The
>  >> class is:
>  >> Metaclass
>>  Okay, question: have you done an inspectIt an all the expressions in  
>> your posting.
>>  For example, when I do an inspectIt on the expression (String class),  
>> I get an instance of Metaclass. In your description, you get an  
>> instance of Metaclass for (String class class)
>
> I don't understand you.
>
> (String class) is an instance of Metaclass
> (String class class) is Metaclass

Ah! You wrote 'String class' is an instance of a class. The class is  
Metaclass.

And I read: ('String class' is an instance of a class), the class of which  
is Metaclass.

You talked about "a class which happens to be Metaclass" and I was  
thinking you sent the message #class ...

> inspecting an object shows its class as a title.
>
> Can you rephrase please so that I understand.
>
>
> I might be wrong :-)

No, not wrong. I was reading it this way, you where writing it that way. A  
bit to many "class" words in the same posting.

I should have asked you instead: do you mean this or do you mean that. Now  
it's clear for me.

--------------

BTW: did you compare the Class/Metaclass schema from Little Smalltalk, it  
has the same class/Metaclass names but a much simpler "class is instance  
of" schema; mentioned in

- http://www.google.com/search?q=little+smalltalk+a+3-metalevel+system

/Klaus

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners