2010/4/1 Denis Kudriashov dionisiydk@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:
Object>>beImmutable self handleMutationBy: [:mutation | self raise: (ModificationException new mutation: aMutation)]
Object>>beMuttable self resetMutationTracking