As I pointed out yesterday, #sort and its immediate relatives
are not alone.  Look at #isSortedBy: .  When do you want
(#(1 1 1) asSortedCollection: b) isSortedBy: b
to answer false?

There are several reasons for sorting.  One is so that you
can use binary search.  It's rather disconcerting that the
binary search offered in Squeak and Pharo has nothing to do
with sortBlocks.  In several other Smalltalks it does.  It
is not terribly hard to write a binary search using a
sortBlock that acts like #<=.  It is not terribly hard to
write a binary search using a sort block that acts like
#<.  It is harder than it needs to be to write a binary
search that can tolerate either, and the one Smalltalk I
know that does this copes by calling the sortBlock twice
as often as it would need to if it knew one way or the other.

As it happens, my own Smalltalk library lets me do
sortBlock := sortBlock converse, which makes it easy
to do the right thing.  It is possible to implement this
so that the result is as cheap to call as the original.

Reply via email to