[squeak-dev] Re: immutibility

Denis Kudriashov dionisiydk at gmail.com
Thu Apr 1 06:37:38 UTC 2010

2010/4/1 Denis Kudriashov <dionisiydk at gmail.com>

> I think usage of immutability for object modification tracking is not very
> well solution and not simple solution. With that you must put every code
> with your objects in block that catch ModificationException. You can't track
> arbitrarily object modifications in any other places of system.
> I think more general approach is registering arbitrary modification handler
> on object mutation like
> object handleMutationBy: [:mutation | ]
> and
> object resetMutationTracking
> And maybe it can be implemented like immutability approach. with single bit
> in object header. VM check this bit for #at:put: like primitives and send
> message #handleMutation: to target object if It set.
> And now immutability logic with ModificationException has very simple
> implementation in language side
> Object>>handleMutation: aMutation
>    self raise: (ModificationException new mutation: aMutation)
> Implementation of my messages:
> Object>>handleMutation: aMutation
>   self trackMutation.
>   ^mutationHandler value: aMutation
> And VM needs two primitives: #trackMutation and #resetMutationTracking
Sorry, I little mistake. What I try wrote is:

Object>>handleMutation: aMutation
  ^mutationHandler value: aMutation

Object>>handleMutationBy: aBlock
  self trackMutation.
  mutationHandler := aBlock

And immutable logic can be like that:

  self handleMutationBy: [:mutation | self raise: (ModificationException new
mutation: aMutation)]

  self resetMutationTracking
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20100401/fc1e00db/attachment.htm

More information about the Squeak-dev mailing list