About Self implicit receiver

ducasse ducasse at iam.unibe.ch
Mon Sep 29 06:15:39 UTC 2003


Thanks all

I simply forget to think about the local variables.

> Avi and Benjamin already gave some good explanations, so I will just 
> add
> some less obvious details. Note that there is a self-interest list at
> YahooGroups, though I don't think the folks here will mind an
> occasional non-Squeak question.
>
> The model that is presented to the programmer (the actual 
> implementation
> is quite different, but totally hidden) is that a method object is
> cloned to create the corresponding context object. When this cloning
> takes place, the method's "self*" slot is set to the receiver of the
> message. The "*" indicates that this is a parent slot, so a message
> sent to the context object and not found there will be looked up in the
> receiver.
>
> So the implicit self is more like "thisContext" in Smalltalk than like
> "self".
>
> Note that block and blockContexts can be exactly like methods and
> contexts except that they have a "lexicalParent*" slots instead of a
> "self*" one. So "self" still refers to the receiver of the outermost
> lexical context, as it should.
>
> Here is what the lookup of the unary message "set" looks like with an
> implicity self receiver inside a nested block:
>
>   thisContext has no 'set' slot=>look in lexicalParent*
>   blockContext has no 'set' slot=>look in lexicalParent*
>   context has no 'set' slot=>look in self*
>   a circleMorph has no 'set' slot=>look in parent*
>   traits circleMorph has no 'set' slot=>look in parent*
>   traits morph has no 'set' slot=>look in parent*
>   traits clonable has no 'set' slot=>look in parent*, cloning*,
> comparing*, ordering*
>   lobby has no 'set' slot=>look in globals*, defaultBehavior*
>   globals has a 'set' slot, so we return that
>
> I didn't follow the branches in the cloning*, comparing*, ordering* or
> defaultBehavior* slots to make things shorter, but in a real lookup all
> parents are searched.
>
> At each step in the lookup, a 'set' slot would correspond to the
> Smalltalk temp/arg, temp/arg, temp/arg, instance variable, class
> variable, class variable, class variable, pool, global and global
> respectively.
>
> So the whole issue, here, is to present a single concept to the
> programmer that can be used in several different situations.
>
> It is interesting that Brian has eliminated the "self*" slot in Slate,
> so that the above lookup would not find the instance and class
> variables. Instead, you have to explicitly send a message to one of the
> arguments (the first one is named, and not "self" though I think you
> can call it that for old time's sake). In Neo Smalltalk I went one step
> further and eliminated the globals.
>
> -- Jecel
>
>



More information about the Squeak-dev mailing list