[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.20 Comparison and sorting

Function: compare obj1 obj2

Generic Function: object-compare obj1 obj2

Function: sort list &optional cmfpn
Function: sort! list &optional cmfpn
Sorts elements in list in ascending order and returns the sorted list. sort! destructively reuses the cons cells of the original list. The sorting order is specified by cmpfn, which is a procedure takes two elements of list, and returns #t if the first argument strictly precedes the second.

 
(sort '(("Chopin" "Frederic") 
        ("Liszt" "Franz")
        ("Alkan" "Charles-Valentin"))
      (lambda (x y) (string<? (car x) (car y))))
  => (("Alkan" "Charles-Valentin")
             ("Chopin" "Frederic")
             ("Liszt" "Franz"))

Some builtin objects have natural comparison order, and it is used if cmpfn is omitted.



This document was generated by Ken Dickey on November, 28 2002 using texi2html