Hi,

On Tue 20 Oct 2009 10:38, l...@gnu.org (Ludovic Courtès) writes:

> Andy Wingo <wi...@pobox.com> 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”.

(sort l < #:key cdr) is a bit contrived. But 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. It's
part of our old Lisp tradition :)

Plus.. it's for occupational safety. Less typing for the win! :)

Andy
-- 
http://wingolog.org/


Reply via email to