XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

sort


Type:   -   function (subr)
Source:   -   xllist.c

Syntax

(sort list test)
list - a list containing elements to be sorted
test - the test to use for the sort
returns - the sorted list

Description

The 'sort' function sorts the 'list' using the 'test' to order the list. The 'sort' function is destructive and modifies the 'list'.

Examples

(setq a '(3 1 4 1 5 9 6 7))          ; returns (3 1 4 1 5 9 6 7)

(sort a '<)                          ; returns (1 1 3 4 5 6 7 9)

(print a)                            ; returns (1 1 3 4 5 6 7 9)
                                     ; notice that A is modified

(sort a '>)                          ; returns (9 7 6 5 4 3 1 1)

(sort '("a" "bar" "foo") 'string>)   ; returns ("foo" "bar" "a")

Bug: XLISP returns the proper value, but improperly modifies the symbol or actual 'list'. [I still haven't tested this with Nyquist.]

Common Lisp: Common Lisp allows for a ':key' keyword, which allows a specified function to be run before the ordering takes place, which XLISP does not support.

See the sort function in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next