SWI-Prolog, version 6.6.6.
Consider the following facts:
p(a, a).
p(a, b).
It results in the following answer:
?- p(a, a).
true ;
false.
But if I slightly change the data:
p(a, a).
p(b, a).
I get a slightly different answer...
?- p(a, a).
true.
It seems that backtracking in the second case does not occur because the first parameter of the predicate in the question does not unify with the other clauses.
Nevertheless, one would expect to have the answer true ; false.
for each case: the engine would try the first predicate clause (resulting in true
), then backtrack and look for other clauses for the same predicate (resulting in false
). Is it a kind of a shortcut in the second case?
Is this a (somewhat) standard behavior - i.e. should be considered when writing prolog rules -, or is it purely implementation-specific?