[squeak-dev] Re: Dictionary>>collect: returning OrderedCollection?
nicolas cellier
ncellier at ifrance.com
Thu Jun 12 22:29:40 UTC 2008
Hans-Martin Mosner a écrit :
> 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.
Agree, I fully support Andreas request as a very logical one.
Beside, it is very easy to get an OrederedCollection if that is really
wanted in Squeak:
(dict collect:[:item| item asWords]) asOrderedCollection.
or:
dict values collect:[:item| item asWords]
> One possible reason why #collect returns a different kind of collection
> is that for some base collections, the results of the block might not
> fit (for example, "aByteArray collect: [:x | x odd]" would raise an
> exception).
True, but since Dictionary can hold any arbitrary value...
I think that historical reason is that #do: only iterates on values, and
that super #collect: was implemented with a #do: loop...
And long ago, values would answer a Bag because Dictionary keys are
unordered (I guess Dictionary species would ^Bag, but no old image here
to check...)
> Incidentally, VisualWorks behaves as you and I expect.
>
Only recently, because 7.2 did still return an OrderedCollection...
> Cheers,
> Hans-Martin
>
>
Nicolas
More information about the Squeak-dev
mailing list
|