Re: sort function

From: Thomas A. Russ (tar_at_sevak.isi.edu)
Date: 01/05/04


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


Relevant Pages

  • RE: automatic data sorting?
    ... I did that and must be missing something. ... I used the macro recorder and set a hot key. ... Notice, you are going to sort based on the values in Colun B, and the sort ...
    (microsoft.public.excel.worksheet.functions)
  • Re: C in Science and Engineering...
    ... That's because this sort of template is ugly as sin. ... You are completely missing the point here. ... argument "a" is the number of hits since last checkin. ... void gen_report ...
    (comp.lang.c)
  • RE: automatic data sorting?
    ... I used the macro recorder and set a hot key. ... didn't happen and I am sure I am missing something I was supposed to have ... Notice, you are going to sort based on the values in Colun B, and the sort ...
    (microsoft.public.excel.worksheet.functions)
  • Re: IDing parts, finding specific schematics... need some help
    ... A resistance or something? ... broken PS2 with that part missing. ... this sort of thing. ...
    (sci.electronics.repair)
  • Re: SSIS Merge Join and Sortkeyposition
    ... > You may have already covered this, but sorting in the OLE-DB Source ... Not sure at this time if the is a 'feature' or I am missing something. ... you sort the data with a sort component. ...
    (microsoft.public.sqlserver.dts)