sort - part-cw/lambdanative GitHub Wiki
(sort lst cmp)
sort sorts a list using the comparison operator cmp, which can be a function.
Parameter | Description |
---|---|
lst | List to be sorted |
cmp | Comparison operator or function to be used for sorting |
Example
Example 1: Sort a list of numbers
> (define lst (list 5 1 4 3 2 6))
> (sort lst <)
(1 2 3 4 5 6)
Example 2: Sort a list of lists by the second element of that list
> (define lst (list (list 2 1) (list 3 5) (list 1 0)))
> (sort lst (lambda (a b) (< (cadr a) (cadr b))))
((1 0) (2 1) (3 5))