Sorts the elements in a list according to a given compare function
Supported Platforms: Windows and Mac OS
(vl-sort lst comparison-function)
Type: List
Any list to sort.
Type: Subroutine or Symbol
A comparison function. This can be any function that accepts two arguments and returns T (or any non-nil value) if the first argument precedes the second in the sort order. The comparison-function value can take one of the following forms:
Type: List
A list containing the elements of lst in the order specified by comparison-function. Duplicate elements may be eliminated from the list.
Sort a list of numbers:
(vl-sort '(3 2 1 3) '<) (1 2 3)
Note that the result list contains only one 3.
Sort a list of 2D points by Y coordinate:
(vl-sort '((1 3) (2 2) (3 1)) (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))) ((3 1) (2 2) (1 3))
Sort a list of symbols:
(vl-sort '(a d c b a) '(lambda (s1 s2) (< (vl-symbol-name s1) (vl-symbol-name s2)))) (A B C D) ; Note that only one A remains in the result list