up previous next

Sort, Sorted

Syntax

Sort(V:LIST):NULL
Sorted(L:LIST):LIST

where V is a variable containing a list.
    

Summary

sort a list

Description

The first function sorts the elements of the list in V with respect to the default comparisons related to their types; it overwrites V. The second function, Sorted, returns the list of the sorted elements of L without affecting L, itself. For more on the default comparisons, see "Relational Operators" in the chapter on operators. For more complicated sorting, see SortBy, SortedBy.

example

    
L := [3,2,1];
Sort(L);
L;
[1, 2, 3]
-------------------------------
Use R ::= Q[x,y,z];
L := [x,y,z];
Sort(L);
L;
[z, y, x]
-------------------------------
Sorted([y,x,z,x^2]);
[z, y, x, x^2]
-------------------------------
Sorted([3,1,1,2]);
[1, 1, 2, 3]
-------------------------------
Sorted(["b","c","a"]);
["a", "b", "c"]
-------------------------------
Sorted([Ideal(x,y),Ideal(x)]); -- ideals are ordered by containment
[Ideal(x), Ideal(x, y)]
-------------------------------
        
    

See Also