immutability and become (Was: Re: [squeak-dev] immutability)

Igor Stasenko siguctua at gmail.com
Thu Mar 18 05:37:30 UTC 2010


On 18 March 2010 06:51, Markus Lampert <markuslampert at yahoo.com> wrote:
> I would have assumed that an immutable object cannot become anything else. Neither any other object, nor another immutable object. If you can change the state of an object in any way, either by changing it's state directly or by ex-changing it with another object, I would not consider it 'immutable'.
>
Good. This makes it more consistent , except that ex-changing with
another object notion.

So, you saying that i can do:

array := Array with: foo beImmutable.
array at: 1 put: nil.

but can't do:

array := Array with: foo beImmutable.
foo becomeForward: nil.

Why?

> SmallInteger seems to be an immutable object, although probably more a constraint than a design decision.
>
I would consider SmallIntegers to be a naturally immutable objects.
Same as nil, true, false.
But there's another kind of objects which is naturally mutable:

...
thisContext beImmutable.
...

once you do this, you can't advance the computation, because you can't
change a context state.
Stepping to a next instruction altering the state of context, while
immutability bit says that you can't do that.

> Have fun,
> Markus
>
>
>
> ----- Original Message ----
>> As well, as i could simply do:
>
> object isMutable ifFalse: [ object
>> becomeForward: object clone ].
>
> And so, #become becomes a universal tool
>> to defeat an immutability.
>
> On 18 March 2010 06:00, Igor Stasenko <
>> ymailto="mailto:siguctua at gmail.com"
>> href="mailto:siguctua at gmail.com">siguctua at gmail.com> wrote:
>> Yes,
>> i am against adding immutability bit in VM.
>>
>> But if we going that
>> way, then please explain me how VM will respect
>> immutability and
>> #become: or #becomeForward:
>> at the same time.
>>
>> The
>> problem is following:
>> suppose your object (a) is referencing object
>> (b).
>>
>> now you doing:
>>  a beImmutable.
>>
>> and
>> then
>>
>> b becomeForward: c.
>>
>> which leads to
>> replacement of reference to (b) by reference to (c)
>> in an object (a),
>> which is immutable.
>>
>> You could say, lets ignore this.
>>
>> Then, apparently , expect to see a hacky code, which as a workaround
>> of
>> immutability, using #become..
>>
>> --
>> Best regards,
>>
>> Igor Stasenko AKA sig.
>>
>
>
>
> --
> Best regards,
> Igor
>> Stasenko AKA sig.
>
>
>      __________________________________________________________________
> Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now
> http://ca.toolbar.yahoo.com.
>
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list