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

Igor Stasenko siguctua at
Thu Mar 18 13:38:48 UTC 2010

On 18 March 2010 14:32, Bert Freudenberg <bert at> wrote:
> On 18.03.2010, at 06:37, Igor Stasenko wrote:
>> On 18 March 2010 06:51, Markus Lampert <markuslampert at> 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'.
> Right - if the state of the object is changeable by any means, it's not immutable. But if you make it immutable, "becomes" of the objects it references would fail. If your object is mutable but refers to immutable objects, they can still be changed by become. This is not changing the immutable objects, only the objects referring to them.
>> 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.
> No, both of these would work. What you can't do is storing *into* an immutable object.
> #beImmutable needs to be recursive. An immutable object cannot contain a reference to an immutable object.
> Then you just disallow any stores into the immutable object, including becomes:
> immutable := (Array with: 'hi') beImmutable.
> regular := Array with: 'hi' beImmutable.
> immutable first become: 'lo'. "fails"
> regular first become: 'lo'. "succeeds"

But are you sure about recursion?
There's a lot of data structures which will be impossible to use with
such immutability propagation.

For instance, i want to make a single tree node to be immutable. But
once i do that for any node,
it will make a whole tree immutable, since node refers to its parent node.

Even more, what if one of objects keeps a reference to a class? Once
recursive immutability reaches this
object, it will turn about everything in your system into an immutable objects.

> - Bert -

Best regards,
Igor Stasenko AKA sig.

More information about the Squeak-dev mailing list