[ ECLiPSe Term Comparison built-in.|Group Index| Full Index]

compare(?Ordering, ?Term1, ?Term2)

Succeeds if Ordering is a special atom which describes the ordering between Term1 and Term2.

?Ordering
Unifiable to a special atom describing the ordering between Term1 and Term2.
?Term1
Prolog term.
?Term2
Prolog term.

Description

Succeeds if Ordering is one of the special atoms ( '<', '>' or '=') describing the standard prolog ordering between the terms Term1 and Term2:

Ordering is the atom '<' iff Term1 comes before Term2 in the standard ordering.

Ordering is the atom '>' iff Term1 comes after Term2 in the standard ordering.

Ordering is the atom '=' iff Term1 is identical to Term2.

The standard ordering of prolog terms is defined in the following increasing order:

* variables: Comparing free variables yields an undefined result.

* reals: from MINREAL to MAXREAL

* integers: from MININT to MAXINT

* strings: lexicographical (ASCII) order

* atoms: lexicographical (ASCII) order

* compound terms: first by arity, then by functor name, then by the arguments in left to right order.

Fail Conditions

Fails if Ordering does not match the standard ordering between Term1 and Term2.

Resatisfiable

No.

Exceptions

Examples


   Success:
   compare(X, A, a), X = '<'.
   compare(X, a, A), X = '>'.
   compare('<', a(1,2), b(1,2)).
   compare(X, 1, 1), X = '='.
   compare(X, f(1), f(1)), X = '='.
   compare('<', 3.0, 2).
   compare('>', [a,b], [a|b]).
   compare('>', [a,b], [a|X]).
   Fail:
   compare('<', atomb, atoma).
   compare('=', 0, 1).
   compare('>',1.0,1).


See Also

@> / 2, @< / 2, @=< / 2, @>= / 2