Builtin predicates - Term comparison
Predicates in this group take two terms as arguments and succeed without modification if the terms have a specified relationship. Most of the predeciates use the "term-precedes" relationship to order the two terms, which is defined as follows:
- Variables precede all floating-point numbers, which precede all integers, which precede all strings, which precede all atoms, which precede all compound terms, which precede all objects, which precede all predicates.
- Variables and objects are ordered on pointer.
- Integers and floating-point numbers are ordered according to their numeric value.
- Atoms and strings are ordered on their name using strcmp().
- Compound terms (functors and lists) are ordered according to their arity. If the arity is the same, then the compound terms are ordered on their functor names. If the arity and functor names are the same, then the compound terms are ordered on the arguments from left to right.
- List terms have arity 2 and "." as their functor name.
(==)/2, (!==)/2, (@<)/2, (@<=)/2, (@>)/2, (@>=)/2
(==)/2 - tests if two terms are identical.
- Usage
- Term1 == Term2
- Description
- If Term1 and Term2 are identical, then Term1 == Term2 succeeds with no modification to Term1 or Term2. Fails otherwise.
- Examples
X == X succeeds
X == Y fails
f(X,Y) == f(X,Y) succeeds
f(Y,X) == f(X,Y) fails
- Compatibility
- Standard Prolog
- See Also
- (!==)/2, (@<)/2, (@<=)/2, (@>)/2, (@>=)/2
(!==)/2 - tests if two terms are not identical.
- Usage
- Term1 !== Term2
- Term1 \== Term2
- Description
- If Term1 and Term2 are not identical, then Term1 !== Term2 succeeds with no modification to Term1 or Term2. Fails otherwise.
- Examples
X !== X fails
X !== Y succeeds
f(X,Y) !== f(X,Y) fails
f(Y,X) !== f(X,Y) succeeds
- Compatibility
- The (\==)/2 predicate is from Standard Prolog. The new name (!==)/2 is the recommended spelling.
- See Also
- (==)/2, (@<)/2, (@<=)/2, (@>)/2, (@>=)/2
(@<)/2 - tests if the first argument term-precedes the second.
- Usage
- Term1 @< Term2
- Description
- If Term1 term-precedes Term2, then Term1 @< Term2 succeeds with no modification to Term1 or Term2. Fails otherwise.
- Examples
f(j) @< f(k) succeeds
f(k) @< f(j) fails
f(j) @< f(j) fails
2.0 @< 1 succeeds
- Compatibility
- Standard Prolog
- See Also
- (==)/2, (!==)/2, (@<=)/2, (@>)/2, (@>=)/2, term-precedes
(@<=)/2 - tests if the first argument is identical to or term-precedes the second.
- Usage
- Term1 @<= Term2
- Term1 @=< Term2
- Description
- If Term1 is identical to or term-precedes Term2, then Term1 @<= Term2 succeeds with no modification to Term1 or Term2. Fails otherwise.
- Examples
f(j) @<= f(k) succeeds
f(j) @<= f(j) succeeds
f(k) @<= f(j) fails
2.0 @<= 1 succeeds
- Compatibility
- The (@=<)/2 predicate is from Standard Prolog. The new name (@<=)/2 is the recommended spelling.
- See Also
- (==)/2, (!==)/2, (@<)/2, (@>)/2, (@>=)/2, term-precedes
(@>)/2 - tests if the second argument term-precedes the first.
- Usage
- Term1 @> Term2
- Description
- If Term2 term-precedes Term1, then Term1 @> Term2 succeeds with no modification to Term1 or Term2. Fails otherwise.
- Examples
f(j) @> f(k) fails
f(k) @> f(j) succeeds
f(j) @> f(j) fails
2.0 @> 1 fails
- Compatibility
- Standard Prolog
- See Also
- (==)/2, (!==)/2, (@<)/2, (@<=)/2, (@>=)/2, term-precedes
(@>=)/2 - tests if the second argument is identical to or term-precedes the first.
- Usage
- Term1 @>= Term2
- Description
- If Term2 is identical to or term-precedes Term1, then Term1 @>= Term2 succeeds with no modification to Term1 or Term2. Fails otherwise.
- Examples
f(j) @>= f(k) fails
f(j) @>= f(j) succeeds
f(k) @>= f(j) succeeds
2.0 @>= 1 fails
- Compatibility
- Standard Prolog
- See Also
- (==)/2, (!==)/2, (@<)/2, (@<=)/2, (@>)/2, term-precedes