| Did you know ... | Search Documentation: |
| Predicate partial_compare/3 |
undecided(Sub1, Sub2), where Sub1
and
Sub2 are the first pair of subterms of Term1 and Term2
that could not be compared. Because the standard order compares terms
lexicographically, this pair decides the entire comparison: after any
further instantiation, compare(Order, Term1, Term2) gives
the same result as compare(Order, Sub1, Sub2), unless Sub1
and
Sub2 become equal (==/2), in which case the comparison must
continue with the remaining subterms.
If the two terms are cyclic and have no order (see
section 4.6.1), Order
is unified with
incomparable(Sub1, Sub2), where Sub1 and Sub2
are a pair of subterms at which the lexicographic comparison runs into a
cycle. Unlike undecided(Sub1, Sub2), further instantiation
cannot make the terms comparable.
?- partial_compare(Order, f(a,1), f(a,2)). Order = (<). ?- partial_compare(Order, f(a,X), f(a,b)). Order = undecided(X, b). ?- partial_compare(Order, f(X,1), f(X,2)). Order = (<). ?- partial_compare(Order, f(_,1), g(_,2)). Order = (<). ?- A = s(B,0), B = s(A,1), partial_compare(Order, A, B). A = s(s(A, 1), 0), B = s(A, 1), Order = incomparable(s(s(A, 1), 0), s(A, 1)).
The last two queries illustrate that a variable only makes the comparison undecided if it is actually reached: the first of these compares the same variable to itself and continues with the second argument, while the second is decided by the functor name before the arguments are examined at all.