Next: Copying, Previous: Object Properties, Up: Utility Functions
Sorting is very important in computer programs. Therefore, Guile comes
with several sorting procedures built-in. As always, procedures with
names ending in ! are side-effecting, that means that they may
modify their parameters in order to produce their results.
The first group of procedures can be used to merge two lists (which must be already sorted on their own) and produce sorted lists containing all elements of the input lists.
Merge two already sorted lists into one. Given two lists a and b, such that both
(sorted? a less?)and(sorted? b less?)are true, return a new list in which the elements of a and b are stably interleaved so that(sorted? (merge a b less?) less?)would be true. Note: This procedure does not accept vectors.
Take two lists a and b such that
(sorted? a less?)and(sorted? b less?)are true, and return a new list in which the elements of a and b are stably interleaved so that(sorted? (merge a b less?) less?)would be true. This is the destructive variant ofmerge. Note: This procedure does not accept vectors.
The following procedures can operate on sequences which are either
vectors or list. According to the given arguments, they return sorted
vectors or lists, respectively. The first of the following procedures
determines whether a sequence is already sorted, the other sort a given
sequence. The variants with names starting with stable- are
special in that they maintain a special property of the input sequences:
If two or more elements are the same according to the comparison
predicate, they are left in the same order as they appeared in the
input.
Return
#tiff items is a list or a vector such that for all1 <=i<=m, the predicate less returns true when applied to all elements i- 1and i.
Sort the sequence items, which may be a list or a vector. less is used for comparing the sequence elements. This is not a stable sort.
Sort the sequence items, which may be a list or a vector. less is used for comparing the sequence elements. The sorting is destructive, that means that the input sequence is modified to produce the sorted result. This is not a stable sort.
Sort the sequence items, which may be a list or a vector. less is used for comparing the sequence elements. This is a stable sort.
Sort the sequence items, which may be a list or a vector. less is used for comparing the sequence elements. The sorting is destructive; i.e., the input sequence is modified to produce the sorted result. This is a stable sort.
The procedures in the last group only accept lists or vectors as input, as their names indicate.
Sort the list items, using less for comparing the list elements. This is a stable sort.