Sorting

This chapter describes the (r6rs sorting)library for sorting lists and vectors.

procedure:  (list-sort proc list) 
procedure:  (vector-sort proc vector) 

Proc must be a procedure that accepts any two elements of the list or vector. This procedure should not have any side effects. Proc returns a true value when its first argument is strictly less than its second, and #f otherwise.

The list-sort and vector-sort procedures perform a stable sort of list or vector, without changing list or vector in any way. The list-sort procedure returns a list, and vector-sort returns a vector. The results may be eq? to the argument when the argument is already sorted, and the result of list-sort may share structure with a tail of the original list. The sorting algorithm performs O(n lg n) calls to the predicate where n is the length of list or vector, and all arguments passed to the predicate are elements of the list or vector being sorted, but the pairing of arguments and the sequencing of calls to the predicate are not specified.