up previous next
sort

sort a list

Syntax
sort(V: LIST)

where V is a variable containing a list.

Description
This function sorts the elements of the list in V with respect to the default comparisons related to their types; it overwrites V and returns NULL.

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(ref L);  -- this returns nothing and modifies L
/**/  L;
[1, 2, 3]

/**/  Use R ::= QQ[x,y,z];
/**/  L := [x,y,z];
/**/  sort(ref L);  -- this returns nothing and modifies L
/**/  L[1];
z

/**/  sorted([y, x, x^2]);   -- this returns the sorted list
[y, x, x^2]

See Also