[squeak-dev] A puzzle for the New Year

David T. Lewis lewis at mail.msen.com
Fri Jan 2 16:07:22 UTC 2015


On Fri, Jan 02, 2015 at 12:01:24PM +0100, Trygve Reenskaug wrote:
> Hi,
> I had to dive into  the deeper regions of Smalltalk when I was preparing 
> BabyIDE for Monticello. I needed to specialize a class /fileOut /method:
> 
>    BB5aMoneyTransferContext>>fileOutOn: aFileStream moveSource:
>    moveSource toFile: fileIndex initializing: aBool
>         super fileOutOn: aFileStream moveSource: moveSource toFile:
>    fileIndex initializing: aBool.
>         <my own additions>
> 
> This works, but the /fileOutOn:moveSource:toFile:initializing:/-method 
> is defined in class /Class/ which is not a superclass of 
> /BB5aMoneyTransferContext/. So /super /does not refer to the superclass! 
> What's going on?
> --------------------------------------------------
> There are two essential object structures in Smalltalk: The 
> instantiation tree and the class inheritance tree. They are independent 
> but intertwined as described in chapter 16 of the Blue Book. It's pretty 
> complicated in the general but fairly obvious in this concrete example.
> 
> Smalltalk is all about objects, not classes.  I used my /Smalltalk 
> Reverse Engineering (SRE)/ tool and produced the attached object 
> diagram. The notation in the diagram is
> 
>  * a rectangle represents an object
>  * the object's name is [<oop>] : <class name>
>  * a line represents a link. An 'instanceOf' relationship is marked
>    //self class/; an inheritance relationship is marked /superclass/.
> 
> The diagram shows that the answer to the puzzle is one 'instaceOf' 
> relationship followed by four  'superclass' relationships. The departure 
> from the usual is that while most class objects are instances of their 
> own  Metaclass. ProtoObject is an exception. It has no superclass, but 
> its metaclass has. It is class Class. Add to this that when an object 
> receives a message, it goes to its class to find the corresponding 
> method. [1224]:MoneyTransferContext  receives the super fileout message. 
> The VM goes to  the superclass of its class, [3253]:Metaclass and looks 
> for the required method in its methodDict. It doesn't find it and 
> continues up the superclass chain until it finds it in [1254]:Class 
> class . Straight forward, isn't it.
> 
> I hope you enjoy this dive into the innards of Smalltalk and wish you 
> all A Happy New Year!
> --Trygve

Very nice illustration. It's interesting that you were able to generate
the diagram automatically and produce a very clear diagram to show the
relationships.

Dave



More information about the Squeak-dev mailing list