Neat! Actually, I did something similar to this a couple years ago to try and
solve the "printString problem." (i.e.: traits point could have a
slot printString = (x printString, '@', y printString). But
this would not work for traits point itself -- it does not have an x or y)
I think the story has some interesting morals.
The idea was simple: by looking at the messages sent to self in the
printString method, you could decide if the object implements all the
necessary behavior to print itself using that method. If not, it could print
some other way.
So I implemented this, and the first thing I did was try to print traits
point. I expected it would find no x or y, so it would bail out and
print out as "traits point." But I got something like "nil @ a
What happened!? I had two slots in my lobby called x and y, put there to
hold random stuff I was interested in. Almost everything inherited these
slots, giving almost everything the protocal of a point. Including
traits point, of course.
By the way, does your scheme deal with recursively following the sends
to self? Also, dynamic inheritance could be a bumer.
> From Bay.Chang@Eng Thu Nov 17 09:53 PST 1994
> Resent-Date: Fri, 11 Nov 94 17:09:26 GMT
> Resent-From: Bay.Chang@Eng (Bay-Wei Chang [CONTRACTOR])
> Resent-Message-Id: <9411171748.AA12533(a)traits.Eng.Sun.COM>
> Resent-To: real-self-interest(a)self.stanford.edu
> From: Ivan Moore <ivan(a)cs.man.ac.uk>
> To: self-interest(a)self.stanford.edu
> Cc: trevor(a)cs.man.ac.uk
> Subject: interesting discovery
> Date: Fri, 11 Nov 94 17:09:26 GMT
> Content-Type: text
> Content-Length: 1694
> Hello Self-interested people,
> This mailing list has been a bit quiet - so here's a little something
> that I thought was quite interesting.
> Want to find out what slots an object needs to define, in order to inherit
> from a traits object? (ie. the equivalent of 'subclassResponsibility' and
> what 'instance variables' are needed (sorry - that's just Smalltalk speak
> to try to make it clearer)
> For all methods in the traits object and all the methods it inherits
> build up a set of all messages they send to implictSelf (easy to work out from
> the bytecode vector)
> (actually its not all messages sent to implicitSelf - you have to take away
> those which are arguments or temporary/local slots (whatever they are called))
> take away from this the full protocol of the traits object (ie. all the
> messages it understands including those inherited), et voila.
> I wrote some code to do this - and it seems to work.
> a traits point child needs 'x' and 'y'
> a traits dictionary child needs lots of things = 'myKeys:' 'size:' ETC
> (they make sense after looking at what slots a dictionary does actually define)
> BTW - I realise that there are some improvements that could be made to this
> ie. messages sent to explicit self and messages sent to the result of message
> sends that return self should be included - but in practice I think what I've
> described does a reasonable job.
> There is a problem if you go around defining methods of the
> form 'x = ( childResponsibility )' !!!
> If this isnt clear, sorry. Please tell me and I'll have another go at
> explaining it.
> ps. I seem to remember Ole Lehrman Madson asked a similar question when I
> met him last summer. Hello Ole, and the rest of the group.