IdentityDictionary reset
Ciao, in the Pharo 4.0 image i have a IdentityDictionary with ten items. Now when i reset the dictionary the system behaves as follows: Version A) resetAllLocks locks keysAndValuesDo:[:k :v | locks removeKey: k ifAbsent: [self halt]] Not all items are removed fro the dictionary. Version B) resetAllLocks locks keys do:[:k | locks removeKey: k ifAbsent: [self halt]] All the items are always removed. Considerations about it? Thanks, Dario
Hi Dario, On 9 April 2018 at 10:00, Trussardi Dario Romano <dario.trussardi@tiscali.it> wrote:
Ciao,
in the Pharo 4.0 image i have a IdentityDictionary with ten items.
Now when i reset the dictionary the system behaves as follows:
Version A) resetAllLocks
locks keysAndValuesDo:[:k :v | locks removeKey: k ifAbsent: [self halt]]
Not all items are removed fro the dictionary.
Version B) resetAllLocks
locks keys do:[:k | locks removeKey: k ifAbsent: [self halt]]
All the items are always removed.
Considerations about it?
The first version modifies the collection while iterating over it - generally a bad thing to do. The second version creates a new collection of keys and then uses it to remove the items - much safer. If you set a breakpoint in the methods and step into each message send you'll be able to see the difference. Cheers, Alistair
There is #removeAll. You should also check out #keysAndValuesRemove: Removing from a collection while iterating over it is dangerous.
On 9 Apr 2018, at 10:00, Trussardi Dario Romano <dario.trussardi@tiscali.it> wrote:
Ciao,
in the Pharo 4.0 image i have a IdentityDictionary with ten items.
Now when i reset the dictionary the system behaves as follows:
Version A) resetAllLocks
locks keysAndValuesDo:[:k :v | locks removeKey: k ifAbsent: [self halt]]
Not all items are removed fro the dictionary.
Version B) resetAllLocks
locks keys do:[:k | locks removeKey: k ifAbsent: [self halt]]
All the items are always removed.
Considerations about it?
Thanks,
Dario
Hello Can you let us know why you are using pharo 40? It is around at least three years old and we made a lot of progress in the last 3 years. Stef On Mon, Apr 9, 2018 at 10:00 AM, Trussardi Dario Romano <dario.trussardi@tiscali.it> wrote:
Ciao,
in the Pharo 4.0 image i have a IdentityDictionary with ten items.
Now when i reset the dictionary the system behaves as follows:
Version A) resetAllLocks
locks keysAndValuesDo:[:k :v | locks removeKey: k ifAbsent: [self halt]]
Not all items are removed fro the dictionary.
Version B) resetAllLocks
locks keys do:[:k | locks removeKey: k ifAbsent: [self halt]]
All the items are always removed.
Considerations about it?
Thanks,
Dario
participants (4)
-
Alistair Grant -
Stephane Ducasse -
Sven Van Caekenberghe -
Trussardi Dario Romano