Name

sort — Sort list using an expression

Synopsis

list sort ( any x ,
  any y ,
  list LIST ,
  block EXPR );
 

Parameters

any x

any y

list LIST

block EXPR

Return

list

Description

Sorts the list LIST. You have to specify an order on the list elements by naming formal variables x and y and specify an expression EXPR that evaluates to a boolean value depending on x and y. Return true if x>y to sort the list ascending.

The comparison must be an irreflexive one, that is ">" instead of ">=".

It is because we no longer use bubblesort (yuck) but std::sort which requires a <ulink url="href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">strict weak ordering</ulink>.

Usage

  sort (integer x, integer y, [ 3,6,2,8 ], ``(x < y)) -> [ 2, 3, 6, 8 ]
  sort (string x, string y, [ "A","C","B" ], ``(x > y)) -> ["C", "B", "A"]