[ 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
sort(L1,L2) is equivalent to sort(0,<,L1,L2).
sort(L1,L2) differs from msort(L1,L2) in that it removes duplicates.
Fail Conditions
Fails if List2 does not unify with the sorted list version of List1.
Resatisfiable
No.
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