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

Eliot Miranda eliot.miranda at
Thu Mar 18 16:54:16 UTC 2010

On Thu, Mar 18, 2010 at 5:32 AM, 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.

THis is Gilad's desire for Newspeak.  It cam be implemented at the image
level by traversing the object graph and setting immutability for each
reachable object (excluding the references to classes form instances of
course).  Again the same VM support can serve.  Much better maintainng the
visited set in Smalltalk than in a VM primitive that does the same thing
blindly.  i.e. at the mage level it is much easier to manage the fact that
it is an error to attempt to make certain objects immutable (e.g.

I think also that "An immutable object cannot contain a reference to an
immutable object." is an ideal, not an absolute.  Consider some immutable
object that maintains a memo cache of some time-and-space-consuming
computations.  We might want to void entries n the cache to keep its total
space consumption down.  While the object functions as an immutable one the
memo cache is mutable state but doesn't render the object mutable because it
is only a cache of results of some computation, not essential state in the


> 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"
> - Bert -
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Squeak-dev mailing list