Gotcha! And in the way it works in recursive list cases... let's make up an example.
f([], 0).
f([H|T], X):- f(T, Y), g(H,Z), X is Y+Z.
g(a, 1).
g(X, 0).
inputting f([a,b,a],X), write(X), fail. to this will give you something like...
2110. It will get the first 2, fail. go back and instead...
Sorry, 14. That was a mistake on my behalf.
So what you're saying is that the fail predicate doesn't make it start the whole second rule over again, but only checks for a new b(Y)?
the second rule is executed at the last point of choice : fact with b ==> 4
fail"
This step does not make logical sense to me. Why would this not print 2, 4?
The fail predicate seems a bit unpredictable under certain cases to me. Take the following example.
Code:
a(1).
a(2).
b(3).
b(4).
go:- a(X), write(X).
go:- a(X), write(X), b(Y), write(Y).
Query this with ?- go, fail.
The result is 12134234. How does this make sense? Can somebody explain the...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.