About Self implicit receiver

Benjamin Schroeder benschroeder at acm.org
Sun Sep 28 19:52:47 UTC 2003


On Sunday, September 28, 2003, at 12:28  PM, ducasse wrote:

> Hi
>
> I need the wisdom and knowledge of a Self expert. In the manual it is 
> written:
>
> 	"Unary, binary, and keyword messages are frequently written without 
> an explicit receiver. Such
> messages use the current receiver (self) as the implied receiver. The 
> method lookup, however, begins
> at the current activation object rather than the current receiver. 
> Thus, a message sent explicitly to self is not equivalent to an 
> implicit-receiver send because the former won't search local slots 
> before searching the receiver."
>
> And I have problems to get an example showing the difference.

I'm strictly a novice at Self, but here is my guess as to what the 
manual is saying.  Say you have an object with a "color" slot set to 
the string 'red'.  In its evaluator, if you evaluated

	| color |
	color

you'd get nil, the value of the local, but if you evaluated

	| color |
	self color

you'd get 'red'.  (That example works for me in Self VM version 4.1.11 
on Mac OS X.)

If you just evaluated

	color

you'd also get 'red', because there's no local variable declared.

If I recall correctly, Self treats local variables as instance 
variables of the method activation context.  The twist is that the 
activation context inherits from the object receiving a message, so 
lookup of the receiver's slots proceeds transparently.

So the lookup for "color" first looks for a local, that is, an instance 
variable of the activation; and then it looks in the receiver.

"self" refers directly to the receiver and so "self color" finds the 
receiver's slot.

Hope this helps,
Ben Schroeder



More information about the Squeak-dev mailing list