Lexical Comparison

Lexical comparison allows comparing terms without an attempt to instantiate the terms. These predicates are therefore meta-logical. The predicates (==)/2 and (\==)/2 perform an equality test. The predicates (@<)/2, (@=<)/2, (@>)/2 and (@>=)/2 use a linear ordering based on a lexical comparison. The lexical comparison first looks on the basic type of the involved terms. The ordering of the basic types is as follows:

variable < decimal < float < integer < reference < atom < compound

Variables are ordered according to their internal instantiation numbering. Integers, floats and decimals are arithmetically ordered. But there is no mixing of integers, floats and decimals. Atoms are ordered according to their internal character representation. For compounds first the arity is compared, then the functor is compared and finally the arguments from left to right. The predicate compare/3 returns <, = or >.

Examples:
?- 1 @< 2.0.
No
?- compare(O, 1, 2.0).
O = >

Reference types can always be used in equality tests. Whether a reference type can be compared depends on whether it implements the Java Comparable interface. The predicates locale_compare/[3,4] allow a locale comparison. In locale comparison the atoms and functors are ordered according to a locale specific Java collator. Locale comparison for reference types is not yet supported.

The following built-in predicates are provided:

X == Y: [ISO 8.4.1]
The predicate succeeds when X is lexically equal to Y.
X \== Y: [ISO 8.4.1]
The predicate succeeds when X is not lexically equal to Y.
X @< Y: [ISO 8.4.1]
The predicate succeeds when X is lexically before Y.
X @=< Y: [ISO 8.4.1]
The predicate succeeds when X is lexically before or equal to Y.
X @> Y: [ISO 8.4.1]
The predicate succeeds when X is lexically after Y.
X @>= Y: [ISO 8.4.1]
The predicate succeeds when X is lexically after or equal to Y.
compare(O, X, Y):  [TC2 8.4.2]
The predicate succeeds when O unifies with the result of comparing X to Y. The result is one of the following atoms <, = or >.
locale_compare(O, X, Y):
locale_compare(C, O, X, Y):
The predicate succeeds when O unifies with the result of locale comparing X to Y. The result is one of the following atoms <, = or >. The quaternary predicate allows specifying a locale C.