Manuscript (Case [Issue]22357) Collection - Dictionary withAll: produces unhelpful results with sequences of associations

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

Manuscript (Case [Issue]22357) Collection - Dictionary withAll: produces unhelpful results with sequences of associations

Pharo Issue Tracker
Manuscript Notification
avatar
First Impression Counts in Project:  Collection: 1. Pharo Image  •  You are subscribed to this case
Dictionary withAll: is implemented in terms of Dictionary>>addAll: which contains a special case to deal with aDictionary addAll: bDictionary. Unfortunately this adaptor produces unexpected results for aDictionary addAll: aSequenceOfAssociations.
Pharo's 2003 method by raok reads
addAll: aKeyedCollection
aKeyedCollection == self ifFalse: [
aKeyedCollection keysAndValuesDo: [:key :value |
self at: key put: value]].
^aKeyedCollection
Andreas Raab changed Squeak's version in 2010 to read
addAll: aCollection
"Include all the associations of aCollection as the receiver's elements. Answer
aCollection. Any collection containing associations can be used as argument."

aCollection == self ifFalse: [
aCollection associationsDo: [:assoc| self add: assoc].
].
^aCollection
Hence in Pharo
Dictionary withAll: { 2 -> 3 } => a Dictionary (1->2->3 )
but in Squeak
Dictionary withAll: { 2 -> 3 } => a Dictionary (2->3 )
The latter feels much more natural and expected. This is born out by looking for all users of Dictionary binding and #withAll:. No one uses Dictionary class>>withAll:, I expect because the behavior is so non-intuitive.

Peter Uhnak notes that this is related to
'abc' collect: [ :each | each -> each asciiValue ] as: Dictionary "a Dictionary(1->$a->97 2->$b->98 3->$c->99 )"
But the fix herein does not address that.
Priority Priority: 5 – Fix If Time Status Status: Work Needed
Assigned To Assigned to: Everyone Milestone Milestone: Later

Go to Case
No longer need updates? Unsubscribe from this case.

Don't want Manuscript notifications anymore? Update your preferences.

Manuscript

_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
https://lists.gforge.inria.fr/mailman/listinfo/pharo-bugtracker