next up previous
Next: Finding all Solutions Up: Built-In Predicates Previous: Set Manipulation

Sorting Lists

sort( +List, -Sorted)

  Succeeds if Sorted can be unified with a list holding the elements of List, sorted to the standard order of terms (see section gif). Duplicates are removed.
msort( +List, -Sorted)

  Equivalent to sort/2, but does not remove duplicates.
keysort( +List, -Sorted)

  List is a list of Key-Value pairs (e.g. terms of the functor `- ' with arity 2). keysort/2 sorts List like msort/2, but only compares the keys. Can be used to sort terms not on standard order, but on any criterion that can be expressed on a multi-dimensional scale. Sorting on more than one criterion can be done using terms as keys, putting the first criterion as argument 1, the second as argument 2, etc.
predsort( +Pred, +List, -Sorted)

  Sorts similar to msort/2, but determines the order of two terms by applying Pred to pairs of elements from List (see apply/2). The predicate should succeed if the first element should be before the second.



Passani Luca
Tue Nov 14 08:58:33 MET 1995