CoCoA:Sort

From ApCoCoAWiki
Revision as of 10:02, 24 October 2007 by XMLBot (talk | contribs) (pushing XML rev. 1.46, again)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Sort

sort 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 <ttref>SortBy</ttref>, <ttref>SortedBy</ttref>.

Example

  L := [3,2,1];
  Sort(L);  -- this returns nothing and modifies L
  L;
[1, 2, 3]
-------------------------------
  Use R ::= Q[x,y,z];
  L := [x,y,z];
  Sort(L);  -- this returns nothing and modifies L
  L[1];
z
-------------------------------
  Sort([y,x,z,x^2]);  -- this returns nothing!!
  Sorted([y,x,x^2]);  -- this returns the sorted list
[y, x, x^2]
-------------------------------

Syntax

Sort(V:LIST):NULL

where V is a variable containing a list.

Relational Operators

Sorted

SortBy

SortedBy

   <type>list</type>