Consider the following code:
a(X) :- b(X),!,c(X),fail.
a(X) :- d(X).
b(1).
b(4).
c(1).
c(3).
d(4).
The query a(X).
produces
1 ?- a(X).
false.
2 ?-
but with this code
a(X) :- b(X),!,c(X).
a(X) :- d(X).
b(1).
b(4).
c(1).
c(3).
d(4).
The query a(X).
results in :
1 ?- a(X).
X = 1.
So my question is, why does the fail/1
produces false? it is supposed to force backtracking, right ? then b(1)
and c(1).
would be checked, I think, so why does it fail?
cut/1
checks onlyX=1
, doesn't it ? then it would check bothb(1)
andc(1)
. Am I wrong ? – Wriest