Re: [Pharo-users] Is it possible to follow an object through a computation?
Hi Paul, You can set the object to be "read only" (aka "immutable") and handle the exception. E.g. | u | u := User named: 'Paul'. u beReadOnlyObject. [ "your code modifying u's state" ] on: ModificationForbidden do: [ :ex | ex halt. "inspect state" u beWritableObject. ex resume ]. Probably there is a better way to do this with slots, using default ones or subclassing `InstanceVariableSlot` for that instance only and halting on the `write:to:` method of it. Regards, Esteban A. Maringolo El mié., 2 ene. 2019 a las 15:45, PAUL DEBRUICKER via Pharo-users (< pharo-users@lists.pharo.org>) escribió:
Hi -
Is there a way to haltOnChange or some such for an object?
I have an instance that gets into a state I don't understand and would like to watch it or several of its inst vars for when they change.
I could set a lot of #haltIf: statements and step through but hope someone has a better strategy
thanks & happy new year.
Paul
On 3 Jan 2019, at 03:17, Esteban Maringolo <emaringolo@gmail.com> wrote:
Hi Paul,
You can set the object to be "read only" (aka "immutable") and handle the exception.
E.g.
| u | u := User named: 'Paul'. u beReadOnlyObject. [ "your code modifying u's state" ] on: ModificationForbidden do: [ :ex | ex halt. "inspect state" u beWritableObject. ex resume ].
Probably there is a better way to do this with slots, using default ones or subclassing `InstanceVariableSlot` for that instance only and halting on the `write:to:` method of it.
I started an experiment to turn the read Only mechanism into a general object change notifier: https://github.com/MarcusDenker/ChangeDetector This allows the following style of use: testObserveObjectWithModification [ | observed observer | observed := 'test2'. observer := self. observed notifyOnChange: observer. "the observed object is now read only" self assert: (observed isReadOnlyObject). "but we can change it!" observed at: 1 put: $T. self assert: observed equals: 'Test2'. "and the method #objectChangeNotified was called, setting flag" self assert: flag equals: #yes. observed stopNotifyOnChange: observer. self deny: (observed isReadOnlyObject). missing: -> we need to model read only for all tracked object (we need to remember the old state and restore it) -> think about threads⦠is there a problem? Marcus
participants (2)
-
Esteban Maringolo -
Marcus Denker