[squeak-dev] The Inbox: Collections-ct.947.mcz

christoph.thiede at student.hpi.uni-potsdam.de christoph.thiede at student.hpi.uni-potsdam.de
Mon Aug 30 17:56:02 UTC 2021


Hi Levente,

> It's not clear to me what you mean by "invert the order of a compare sort block.".

You mentioned that it is possible to pass a BlockClosure instead of a sorting function into something like #sorted:. However, BlockClosures are not fully polymorphic to SortFunctions, so for example, you cannot send #, or #reversed to them.

Regarding the chaining you mentioned, this is indeed not supported, unfortunately. Please see Collections-ct.955 for a second attempt. :-)

Best,
Christoph

---
Sent from Squeak Inbox Talk

On 2021-06-12T21:52:27+02:00, leves at caesar.elte.hu wrote:

> 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
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210830/3fdd8d2c/attachment.html>


More information about the Squeak-dev mailing list