Functions Documentation
View Function Edit Function
Name sort
Syntax (sort list [direction] [keyIndex]) -> list
Argument List list: the list to be sorted
[direction:] the direction in which to sort the list. Can be either 'ascending or 'descending
[keyIndex:] if you have a list of lists and you want to sort by an element of a sublist, specify the keyindex of that element
Returns list: the sorted list
Category list
Description Very useful function for sorting lists of data
Example You can sort a list of numbers
(setq numbers (list 8 7 9 4 6 1))
(sort numbers) -> (1 4 6 7 8 9)
(sort numbers 'descending) -> (9 8 7 6 4 1)
You can sort a list of strings (alphabetically)
(setq strings (list "a" "t" "f" "x"))
(sort strings) -> ("a" "f" "t" "x")
(sort strings 'descending) -> ("X' "t" "f" "a")
You can also sort sublists
(setq sublists (list
(list 5 'five)
(list 3 'three)
(list 9 'nine)
))
(sort sublists 'ascending 0) -> ((3 'three) (5 'five) (9 'nine))
(sort sublists 'ascending 1) -> ((5 'five) (9 'nine) (3 'three))
Comment