[squeak-dev] Not quite literally, let me check the Dictionary...
Igor Stasenko
siguctua at gmail.com
Sun May 2 09:21:53 UTC 2010
On 2 May 2010 11:55, Levente Uzonyi <leves at elte.hu> wrote:
> On Sun, 2 May 2010, Casey Ransberger wrote:
>
>> Aha, thank you. That's why I posted :)
>
> It's actually Dictionary class >> #newFrom: which can create a dictionary
> from an array of associations. There are some examples at the end of the
> method using this feature, but they are flawed, because NewDictionary is not
> a class).
> This feature works because every collection understands #associationsDo:
> (yeah, it's not so nice) and #size, so not just arrays, but any collection
> of associations can be the argument of #newFrom:.
>
Ohh. There is a very bad inconsistency with Collection protocol in Dictionary,
which makes me sad:
| dict array |
dict := Dictionary new.
dict add: 'a' -> 'b'.
self assert: (dict at: 'a') = 'b'.
array := Array with: 'c'->'d'.
dict addAll: array.
self assert: (dict at: 'c') = 'd'
Collection>>addAll: comment reads:
addAll: aCollection
"Include all the elements of aCollection as the receiver's elements. Answer
aCollection. Actually, any object responding to #do: can be used as argument."
Collection>>add: comment reads:
add: newObject
"Include newObject as one of the receiver's elements. Answer newObject.
ArrayedCollections cannot respond to this message."
So, is everyone ok with such dichotomy?
I am certainly not.
If Dictionary takes an association in its #add:
then it should also take a collection of associations in #addAll: ?
And if not, then Dictionary>>add: should not be supported, but
provide alternative method - Dictionary>>addAssociation: .
>
> Levente
>
--
Best regards,
Igor Stasenko AKA sig.
More information about the Squeak-dev
mailing list
|