[squeak-dev] The Inbox: Collections-ct.947.mcz
Levente Uzonyi
leves at caesar.elte.hu
Sat Jun 12 19:52:27 UTC 2021
On Thu, 10 Jun 2021, christoph.thiede at student.hpi.uni-potsdam.de wrote:
> Hi Levente,
>
>> #sort: and #sorted: expect an argument which responds to #value:value: with a boolean, so both of those examples work if you don't send #asCompareSortFunction to the block.
>>
>> However, #asCompareSortFunction may be useful if you want to create chained sort functions. I'm not sure about the name though.
>
> Ouch! I did not see the wood for the trees. :-) But yes, if you would like to, for example, invert the order of a compare sort block, the protocols would not match ... So I guess this would still be relevant.
It's not clear to me what you mean by "invert the order of a compare sort
block.".
However, I see one problem with the implementation. It evaluates the block
but lies about equality. It only returns -1 or 1, never 0. Which means,
chaining is impossible.
Here's an example:
#((1 a) (1 b)) sorted: [ :a | a first ] ascending, [ :a | a second ] descending
"==> #(#(1 #b) #(1 #a)) which is fine"
but
#((1 a) (1 b)) sorted: [ :a :b | a first <= b first ] asCompareSortFunction, [ :a | a second ] descending.
"==> #(#(1 #a) #(1 #b)) which is not what I would expect"
Levente
More information about the Squeak-dev
mailing list
|