[squeak-dev] Re: Dictionary>>collect: returning OrderedCollection?
nicolas cellier
ncellier at ifrance.com
Fri Jun 13 12:08:37 UTC 2008
K. K. Subramaniam a écrit :
> On Friday 13 Jun 2008 3:02:34 am Hans-Martin Mosner wrote:
>> Andreas Raab schrieb:
>>> Does anyone besides me consider this a bug? What does ANSI say about
>>> this issue?
>> I think that #collect: should be in line with #select: and #reject:
>> which both return Dictionaries.
> Why so? #collect; is a closed operation on Collection, not on Dictionary.
> Unlike #select: or #reject:, it aggregates new objects (String in the
> example) generated from the values (Integer). Key associated with the value
> will not carry over to the new object automatically.
>
> Bluebook describes collect: aBlock as:
> <quote>
> Evaluate the argument, aBlock, for each of the receiver's elements. Answer a
> new collection like that of the receiver containing the value returned by the
> block on each evaluation.
> ....
> Messages inherited from the class Collection -- includes:, do: and other
> enumeration messages -- are applied to the *values* of the Dictionary. That
> is, these messages refer to the values of each association in the Dictionary,
> rather than to the keys or to the associations themselves.
> </quote>
>
> Subbu
>
>
From historical POV, you are right, but...
With all the respect due to the holly blue book and its authors, it is
not the bible.
Viewing a Dictionary as a Bag of values certainly was a simple way to
define a compatible Behavior with other collections.
However, it's a much too reductive view that is loosing the Dictionary
spirit. The spirit is associated to the keys undoubtedly.
Let's adopt a more useful behaviour preserving the keys.
And good news, if a Dictionary can be viewed as a Bag of Values, then
collected key/value associations can still be viewed as a Bag of
values... So you don't loose anything, you can still ask for includes:
do: and other Bag-compatible protocol... you only win some associated keys!
Cheers
Nicolas
More information about the Squeak-dev
mailing list
|