On Tue, Feb 21, 2017 at 8:57 PM, Martin Dias <[email protected]> wrote:
> Hi all
>
> Phil:
> I'm sorry, didn't get what you point with the code snippet. The copy of
> the Symbol is the same instance, that I think it's nto GCed.
>
> Guille:
> Yes, I knew the internals of the WeakValueDictionary but asked about the
> API. What I don't know is about using WeakRegistry and Ephemerons. I'll
> check WeakKeyDictionary.
>
> I understand the idea of "explicit control of magic", but not sure if I
> understand concretely. Do you mean to implement something like
> WeakValueDictionary>>register which will not be executed by #initialize,
> so the user can decide to register. Am I right?
>
> Denis:
> +1 WeakSet behavior is really confusing! In thte case of
> WeakValueDictionary I didn't check for inconsistencies but was only annoyed
> but it's behavior.
>
> Guille and Denis:
> Instead of using SetElement or cleaning up the empty
> WeakValueAssociations, what I first thought is to internally consider an
> association with nil as absent. I mean, modify or override some methods
> soem when there is an WeakValueAssociation with value == nil it considers
> it's absent. Concretely, I'd expect:
>
> | dictionary |
> dictionary := WeakValueDictionary with: 'hello' -> 'world' copy.
> Smalltalk garbageCollect.
> {
> dictionary values includes: nil. *---> false *
> dictionary at: 'hello'. * ---> NotFound signal*
> dictionary at: 'hello' ifAbsent: [ 'absent' ].* ---> 'absent'*
> dictionary at: 'hello' ifAbsentPut: [ 'put' ]. *---> 'put'*
> }
>
>
> It's better if I give some context. Look this simplified version of my use
> case:
>
> MyUI>>
> morphAt: key
> cache ifNil: [ cache := WeakValueDictionary new ].
> ^ cache at: key ifPresent: [:cachedValueOrNil | cachedValueOrNil
> ifNotNil: [ cachedValueOrNil ] ifNil: [ cache at: entryReference put: (self
> newMorph: key) ] ] ifAbsent: [ cache at: entryReference put: (self
> newMorph: key) ]
>
> I'd like to only send #newMorph: in ifAbsent: and to avoid the
> ifNotNil:ifNil:
> Like this:
>
> morphAt: key
> cache ifNil: [ cache := WeakValueDictionary new ].
> ^ cache at: key ifAbsent: [ cache at: entryReference put: (self
> newMorph: key) ]
>
>
Bah, better:
morphAt: key
cache ifNil: [ cache := WeakValueDictionary new ].
^ cache at: key ifAbsentPut: [ self newMorph: key ]
> :-)
>
> MartÃn
>