Oblivous caching: DynamicVariable >> #default

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Oblivous caching: DynamicVariable >> #default

marcel.taeumel (old)
Hi, there!

After calling #value:during: for a dynamic variable, the #default result is cached in the env variable of the process. Changing the result of #default will have no effect on #value until the process is killed...

I think, this is wrong... :-/

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: Oblivous caching: DynamicVariable >> #default

marcel.taeumel (old)
This would work:

value: anObject during: aBlock

        | p oldValue defaultUsed |
        p := Processor activeProcess.
        defaultUsed := false.
        oldValue := p environmentAt: self ifAbsent: [defaultUsed := true. nil].
        ^[
                p environmentAt: self put: anObject.
                aBlock value ]
                        ensure: [ defaultUsed ifFalse: [p environmentAt: self put: oldValue] ].
Reply | Threaded
Open this post in threaded view
|

Re: Oblivous caching: DynamicVariable >> #default

marcel.taeumel (old)
Actually, *this* seems to work now:

value: anObject during: aBlock

        | p oldValue defaultUsed |
        p := Processor activeProcess.
        defaultUsed := false.
        oldValue := p environmentAt: self ifAbsent: [defaultUsed := true. nil].
        ^[
                p environmentAt: self put: anObject.
                aBlock value ]
                        ensure: [ defaultUsed
                                        ifTrue: [p environmentRemoveKey: self]
                                        ifFalse: [p environmentAt: self put: oldValue] ].
Reply | Threaded
Open this post in threaded view
|

Re: Oblivous caching: DynamicVariable >> #default

Levente Uzonyi-2
This change looks right to me.

Levente

On Sat, 31 Jan 2015, Marcel Taeumel wrote:

> Actually, *this* seems to work now:
>
> value: anObject during: aBlock
>
> | p oldValue defaultUsed |
> p := Processor activeProcess.
> defaultUsed := false.
> oldValue := p environmentAt: self ifAbsent: [defaultUsed := true. nil].
> ^[
> p environmentAt: self put: anObject.
> aBlock value ]
> ensure: [ defaultUsed
> ifTrue: [p environmentRemoveKey: self]
> ifFalse: [p environmentAt: self put: oldValue] ].
>
>
>
> --
> View this message in context: http://forum.world.st/Oblivous-caching-DynamicVariable-default-tp4802924p4802936.html
> Sent from the Squeak - Dev mailing list archive at Nabble.com.
>
>