[racket-dev] [racket] Feature request: multiple keys in sort

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Jun 11 15:19:16 EDT 2012

A few minutes ago, Robby Findler wrote:
> How about this: until you find the perfect way to do this, we just
> add two new optional keyword arguments to sort that deal with two
> levels of key/sorts? eg:
> 
> (sort lst < #:key first #:key2 second)
> 
> would mean to sort by < for both keys, treating the first position
> in the list as the main one and the second as a secondary one. And
> then we could also have another keyword for specifying a different
> sorting predicate for the second key, too.
> 
> That would actually cover all of the cases that I think I've seen in
> practice.

This looks very limited -- assuming that the direction is the same
seems fine, but I think that it can be common to have different
types[*].  Another point is the question of how it'd interact with
`#:cache-keys?'.  And yet another point is that the actual
implementation (in "racket/private/sort.rkt") is way too "involved" to
add this kind of functionality, so if I add something like that, I'd
do that in the keyword wrapper (top of "racket/private/list.rkt") --
and then I can just as well add the kind of combinator I wrote.  (And
that trivially covers your case.)

So I'll take this as an excited +1 for the idea to add such a
combinator, possibly enough to just go with the version I wrote
(right?).  And if so, any suggestions for a name for the combinator?

([*] As it happens, it looks like the improvement to the docs search
thing that we discussed recently is exactly a case where I'll need to
sort on two keys -- strings and numbers.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the dev mailing list.