[FIX] SortedCollectionFix-sr
Richard A. O'Keefe
ok at cs.otago.ac.nz
Tue Oct 1 23:45:59 UTC 2002
With an eye to producing a new version of SortedCollection,
I spent a couple of hours yesterday going through all of the
methods in SortedCollection + all those inherited from OrderedCollection
+ all those inherited from Collection.
Like other core collection classes, SortedCollection turns out to be,
um, less than robust and less than consistent.
My current "favourite" is this:
s := #(1 2 4) asSortedCollection.
s collect: [:x | x]
==> an OrderedCollection(1 2 4)
s with: s collect: [:x :y | x]
==> a SortedCollection(1 2 4)
Surely they should return the same kind of object!
This is the underlying reason why
s := #(1) asSortedCollection.
s + 1
==> an OrderedCollection(2)
s + #(1)
==> a SortedCollection(2)
which leads to
#(1 2 3) asSortedCollection + #(-2 -4 -6)
==> a SortedCollection(-1 -2 -3)
which is in fact NOT sorted (it has a nil sortBlock).
The simplest solution would seem to be to make #with:collect:
also return an OrderedCollection.
More information about the Squeak-dev
mailing list
|