Re: sort function
From: Thomas A. Russ (tar_at_sevak.isi.edu)
Date: 01/05/04
- Next message: Christopher C. Stacy: "Re: Forward chaining expert system recommendation"
- Previous message: Pascal Costanza: "Version 1.3 of my Lisp Guide"
- In reply to: Dave Seaman: "Re: sort function"
- Next in thread: Christopher C. Stacy: "Re: sort function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 05 Jan 2004 10:53:39 -0800
I seem to be missing part of this thread. I hope I'm not being too
repetitive here.
Dave Seaman <dseaman@no.such.host> writes:
>
> On Fri, 2 Jan 2004 14:49:31 -0000, Steve Ellis wrote:
> > Hi again
>
> [1]> (sort '((9 a) (3 b) (4 c)) #'(lambda (x y) (< (car x) (car y))))
> ((3 B) (4 C) (9 A))
An easier to understand Common Lisp formulation would be to take
advantage of the :key keyword argument to sort for this sort of
comparison operation:
(sort '((9 a) (3 b) (4 c)) #'< :key #'car)
It seems to more modularly declare the intention of the programmer to
sort using the < predicate applied to the CAR of the data structures.
(For completeness I would also worry about destructively modifying a
constant list argument, but for an example it's not worth sweating).
-- Thomas A. Russ, USC/Information Sciences Institute
- Next message: Christopher C. Stacy: "Re: Forward chaining expert system recommendation"
- Previous message: Pascal Costanza: "Version 1.3 of my Lisp Guide"
- In reply to: Dave Seaman: "Re: sort function"
- Next in thread: Christopher C. Stacy: "Re: sort function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|