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

msort(+List1, ?List2)

Succeeds if List2 has the same elements as List1 and is sorted.
+List1
List.
?List2
List or variable.

Description

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

The sort is done according to the standard ordering of terms. Duplicates are not removed. See compare/3 for this standard ordering.

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

Fail Conditions

Fails if List2 does not unify with the sorted list version of List1.

Resatisfiable

No.

Exceptions

(4) instantiation fault
List1 is not instantiated.
(5) type error
List1 is not a list.

Examples

Success:
      msort([3,2,1,2,3],[1,2,2,3,3]).
      msort([2,4,6],L).         (gives L=[2,4,6]).
      msort([2,4,6,1,7,3],L).   (gives L=[1,2,3,4,6,7]).

Fail:
      msort([1,5,3,7],[1,3,7,5]).

Error:
      msort(List1,List2).         (Error 4).
      msort("[1]",L).             (Error 5).



See Also

compare / 3, sort / 2, sort / 4