[ Comparing and Sorting | The ECLiPSe Built-In Predicates | Reference Manual | Alphabetic Index ]

# sort(+List1, -List2)

Succeeds if List2 is the strictly ordered, no duplicates version of List1.

List1
  List.
List2
  List or variable.

## Description

List1 is sorted strictly according to standard term ordering (removing duplicates in the sense of ==/2), and unified with List2.

The sort is done according to the standard ordering of terms. See compare/3 for this standard ordering. Note in particular that numbers are first ordered by their type (integer, float, etc) and only then by their magnitude, i.e. sorting numbers of different types may not give the expected result.

Note sort(L1,L2) is equivalent to sort(0,<,L1,L2). sort(L1,L2) differs from msort(L1,L2) in that it removes duplicates.

### Modes and Determinism

- sort(+, -) is det

## Examples

    Success:
          sort([3,1,6,7,2],S).     (gives S=[1,2,3,6,7]).
          sort([1,3,2,3,4,1],S).   (gives S=[1,2,3,4]).
          sort([f(1,3),h(2,1)],S). (gives S=[f(1,3),h(2,1)]).
          sort(["b",2.0,a(1),1,a],S).
                                (gives S=[2.0,1,"b",a,a(1)]).
    Fail:
          sort([2,1,3,4],[2,1,3,4]).

## See Also

compare / 3, msort / 2, sort / 4, number_sort / 2