
sort - sorts the elements of a list

Calling sequence:
sort(list [ , proc ])

Parameter:
list   --  list
proc   --  procedure

Summary:

sort sorts the elements of a listin ascending order. Optionally a procedure
can be given, which is used to define the ordering of sorting.  If no such
procedure proc is given, then the list is sorted as follows:

 o  A list with real numbersis sorted numerically.

 o  A list with stringsis sorted lexicographically.

 o  In other cases the list is sorted according to the system's internal order.
    This order is unambiguous but not documented. (Such sorting is useful
    when e.g. the user wants to compare two lists in which the sequence of
    the elements need not be identical.)

When strings are being compared it is important to note that in general
capital letters are sorted in front of small letters, thus "ZZ" is smaller than
"a".

If a procedureproc is passed to sort as the second argument then it is used to
compare the elements of the lists. The procedure must have two parameters
and return a Boolean value. The expression proc(a,b) must return TRUE, if
a is to be sorted in front of b.

Sorting is not stable and elements with the same order may be swapped.
The mean run time for sorting n elements is O(n*log(n)). sort is a kernel
function.

>>  sort([4, -1, 2/3, 0.5]);

      [-1, 0.5000000000, 2/3, 4]

>>  sort(["chip", "alpha", "Zip"]);

      ["Zip", "alpha", "chip"]

>>  cmp := proc(a,b) begin bool(abs(a) < abs(b)) end_proc:
    sort([-2, 1, -3, 4], cmp);

      [1, -2, -3, 4]

See also:  insert_ordered

