Hi Marcel,


Preferences does not expose the dictionary. It is rather an implementation detail.


Yes, but #setPreference:toValue:during: *could* reuse #at:put:during: instead of reinventing this - though small - wheel. :-)


there are implementations of #at:put: where a "nil" value deletes the key.


Isn't this a completely domain-specific design decision? I think we should look at this at a different level of abstraction.


I would rather not support modifying the dictionary during "aBlock". Similar to #do: etc. in a collection.


But the semantics of an execution-around method do not need to be timeless as mentioned earlier. Imagine a morph that changes its fill style regularly while stepping, and that should be displayed with a different border style while a dialog window is open. In this example, forbidding the manipulation of extensions during aBlock would rule out the use of #at:put:during: ...


What about this implementation? Seems to so "low level":

Might be less efficient (I haven't measured it) but provides better readability. :-)

Best,
Christoph

Von: Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel
Gesendet: Dienstag, 8. Dezember 2020 13:34:33
An: squeak-dev
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.922.mcz
 
Hmm... Preferences does not expose the dictionary. It is rather an implementation detail. See:

Preferences class >> #setPreference:toValue:
Preferences class >> #setPreference:toValue:during:

Hmm... there are implementations of #at:put: where a "nil" value deletes the key. See:

Morph >> #setProperty:toValue:

Hmm... I am not sure about the returned value. Shouldn't it be the object? Should it the block's last result? Depends on the purpose, I suppose.

Hmm... I would rather not support modifying the dictionary during "aBlock". Similar to #do: etc. in a collection.

What about this implementation? Seems to so "low level":

| hasKey oldValue |
self at: key ifPresent: [:v | oldValue := v. hasKey := true].
self at: key put: anObject.
^ aBlock ensure: [
hasKey == true
ifTrue: [self at: key put: oldValue]
ifFalse: [self removeKey: key]]

Best,
Marcel

Am 07.12.2020 19:14:30 schrieb Thiede, Christoph <christoph.thiede@student.hpi.uni-potsdam.de>:

I wanted to provide it as a general functionality - you could use this in many situations, for example for adding a process variable temporarily, changing a morphic extension temporarily, or maybe even to adjust a preference temporarily ... Where temporary, just for example, might mean for the duration of a test execution (which, of course, might be debugged, so is not necessarily run as an atomic operation). In all these situations, the entire system needs to be kept running without introducing any unintended sandbox effects. :-)


Best,
Christoph

Von: Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von tim Rowledge <tim@rowledge.org>
Gesendet: Montag, 7. Dezember 2020 19:10:11
An: The general-purpose Squeak developers list
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.922.mcz
 


> On 2020-12-07, at 10:05 AM, Thiede, Christoph <Christoph.Thiede@student.hpi.uni-potsdam.de> wrote:
>
> IIUYC this would make it impossible to keep other changes to the dictionary after leaving the execution around method?
Absolutely. Depends on what your deeper purpose is.


tim
--
tim Rowledge; tim@rowledge.org; http://www.rowledge.org/tim
Strange OpCodes: LAG: Load and Garble