From: Russell M. <rus...@ya...> - 2003-11-02 22:46:56
|
This can be handled using the :key keyword arg to sort, like so: (sort '((50 3500) (25 2570) (40 2800)) #'< :key #'first) -russ "David Brynjar Franzson" <fra...@st...> writes: > Hi, I am trying to sort a list containing sublists ((50 3500) (25 2570) (40 > 2800)) based on the first value of each sublist. > > A normal sort-list function is sth like this... > > (defun sort-list (list &optional (pred '<)) > (cond ((null) list) nil ) > ((atom (first list)) (sort list pred)) > (t (cons (sort-list (first list) pred) (sort-list (rest list) > pred))))) > > Being almost completely illiterate in Lisp, I am guessing that I just need > to plugin in sth in the order of "(nth 0 sublist)" somewhere in this > function. > > Any help on this would be greatly appreciated. > > Sincerely, > David B Franzson > fra...@ho... > > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > Does SourceForge.net help you be more productive? Does it > help you create better code? SHARE THE LOVE, and help us help > YOU! Click Here: http://sourceforge.net/donate/ > _______________________________________________ > clisp-list mailing list > cli...@li... > https://lists.sourceforge.net/lists/listinfo/clisp-list |