Trying to understand the cut-fail combination in Prolog, I found the following example and started to play with it:
enjoys(vincent,X) :- big_kahuna_burger(X),!,fail.
enjoys(vincent,X) :- burger(X).
burger(X) :- big_kahuna_burger(X).
burger(X) :- big_mac(X).
burger(X) :- whopper(X).
big_kahuna_burger(b).
big_mac(a).
whopper(d).
I've tried two different queries.
In query 1: enjoys(vincent,b)
, the result is that SWI-Prolog outputs false
which is the expected behavior and it stops, doesn't ask me whether I want for it to search for more solutions.
In query 2: enjoys(vincent,a)
, first SWI-Prolog outputs true
which again is expected, but then it gives me the option to click "next" and it tries to find another solution, then outputs false
.
Why did it give me the option to check for another solution during the second query but not in the first one?
false
, that means it exhaustively searched, so that means in no way there is a solution, hence after afalse
, no solutions can be found anymore. – Willem Van Onsemfalse
is not a solution,false
means it did an exhaustive search, and failed to find anything. Most Prolog systems printfalse
(orno
) to show that the query has ended. – Willem Van Onsem