Re: sort needs a #:key argument

2009-10-21 Thread Andy Wingo
Hello, On Wed 21 Oct 2009 18:06, l...@gnu.org (Ludovic Courtès) writes: > Andy Wingo writes: > >> if your key takes time to >> compute, you need to use the decorate-sort-undecorate idiom, otherwise >> you compute the sort key O(n log n) times instead of O(n) times. > > If you insist: > > (sort

Re: sort needs a #:key argument

2009-10-21 Thread Ludovic Courtès
Hello, Andy Wingo writes: > On Tue 20 Oct 2009 10:38, l...@gnu.org (Ludovic Courtès) writes: > >> Andy Wingo writes: >> >>> (sort '((a . 1) (b . -2) (c . 3)) < cdr) >>> => ((b . -2) (a . 1) (c . 3)) >> >> FWIW I find: >> >> (sort '((a . 1) (b . -2) (c . 3)) >> (lambda (x y) >>

Re: sort needs a #:key argument

2009-10-20 Thread Andy Wingo
Hi, On Tue 20 Oct 2009 10:38, l...@gnu.org (Ludovic Courtès) writes: > Andy Wingo writes: > >> (sort '((a . 1) (b . -2) (c . 3)) < cdr) >> => ((b . -2) (a . 1) (c . 3)) > > FWIW I find: > > (sort '((a . 1) (b . -2) (c . 3)) > (lambda (x y) > (< (cdr x) (cdr y > > m

Re: sort needs a #:key argument

2009-10-20 Thread Ludovic Courtès
Hello, Andy Wingo writes: > (sort '((a . 1) (b . -2) (c . 3)) < cdr) > => ((b . -2) (a . 1) (c . 3)) FWIW I find: (sort '((a . 1) (b . -2) (c . 3)) (lambda (x y) (< (cdr x) (cdr y more in the spirit of not “piling feature on top of feature”. Thanks, Ludo’.

sort needs a #:key argument

2009-10-19 Thread Andy Wingo
Hello, Do you read guile-devel and are looking for a manageable thing to hack? Well how about this. `sort!' needs a #:key argument. I believe you will find more precise specifications in the Common Lisp specifications, but the basic idea is that the comparison function of `sort' opera