My SWI-Prolog knowledge base contains the following three facts:
data(catalog1, mike, deposit, 100).
data(catalog1, bob, deposit, 150).
data(catalog2, mike, deposit, 200).
The query is:
?- data(catalog1, mike, deposit, X).
X = 100 ;
false.
The 1st question:
Why the answer contains a false
? It seems that SWI-Prolog leaves a choice point, but I don’t know where it is. I can use ?- data(catalog1, mike, deposit, X), !
to workaround, but is this necessary?
Also, an interesting fact is that if I remove the 2nd or 3rd fact, then it’s OK.
data(catalog1, mike, deposit, 100).
data(catalog1, bob, deposit, 150).
?- data(catalog1, mike, deposit, X).
X = 100.
data(catalog1, mike, deposit, 100).
data(catalog2, mike, deposit, 200).
?- data(catalog1, mike, deposit, X).
X = 100.
P.s. There is a similar question on stackoverflow, but I can’t reproduce that problem in current SWI-Prolog v8.4.1.
The 2nd question:
For a knowledge base like the above, is it necessary to always create a auxiliary predicate to get value (as a Prolog convention) ?
For example,
data_deposite_get(Catalog, Person, Deposit) :-
data(Catalog, Person, deposit, Deposit), !.
?- data_deposite_get(catalog1, mike, X).
X = 100.
Thanks.