assignment message (Re: [squeak-dev] Re: Selectors with underscores)

Bert Freudenberg bert at freudenbergs.de
Thu Mar 18 14:11:48 UTC 2010


On 18.03.2010, at 09:53, Igor Stasenko wrote:
> 
> 2010/3/18 Stéphane Rollandin <lecteur at zogotounga.net>:
>>> it won't go that way, because #becomeForward: replacing all references
>>> to same object:
>>> 
>>> a := z.
>>> b := z.
>>> (here a and b pointing to same object - z)
>>> 
>>> b := x.
>>> 
>>> now, 'a' should still point to 'z', while 'b' should point to 'x'.
>>> but if you do z becomeForward: x , then both a and b will point to x.
>> 
>> right. that's what I missed :)
>> 
> 
> But, if you add an indirection, that every object slots is a unique objects,
> then you can make an assignment as a message , implemented
> primitively, which replacing its contents, i.e.
> if 'a' is an instance variable of 'object', then
> 
> a := b.  =>  object slotA setValue: b.
> 
> a  => object slotA value

Hehe. Now how do you implement setValue:? ;)

Assignment simply is a meta-operation. If you have the expression

	a := b

then it is totally irrelevant what a points to currently. 'a' just designates where the object refered to by 'b' should be stored.

Assignment is a message to the object that holds a reference, not to the referred object itself. Depending on the kind of variable it can be implemented by sending messages to the appropriate objects.

E.g. this

	| a b |
	a := 42.
	b := a.
	^ b

is fully equivalent to

	| a b |
	a := 42.
	thisContext at: 2 put: (thisContext at: 1).
	^ b

because a and b are temps. In the case of instance variables, assignment is equivalent to #instVarAt:put:. In the case of global variables, it's #value:.

In any case, assignment has *nothing* to do with become.

- Bert -





More information about the Squeak-dev mailing list