1

I wrote the following knowledge base in Prolog:

likes(yamini,chocolate).
likes(anuj,apple).
likes(yamini,book).
likes(john,book).
likes(john,france).

Now, when I consult the above file and try the following commands:

| ?- likes(anuj,apple).      

(1 ms) yes
| ?- likes(yamini,chocolate).

true ? ;

no

I want to understand when does Prolog replies a 'yes' versus when does it replies 'true'.

4

2 回答 2

1

This is an artefact of the toplevel (Prolog command line) implementation. Apparently you implementation says true when it could prove a goal and it is unsure whether there may be more solutions. If it is sure that there is only one solution, it says yes.

Here is what SWI-Prolog does:

?- likes(anuj,apple). 
true.

Prolog could successfully prove the goal likes(anuj,apple) and it is also sure there are no other ways to prove it otherwise one would see something like this:

?- member(X,[1,2]).
X = 1 ; 
X = 2.

where an X that makes the goal true has been found as 1 but there may be other solutions. And indeed there are, namely 2.

Back to our example:

?- likes(yamini,chocolate).
true.
于 2021-02-08T18:42:14.157 回答
1

That output depends on the toplevel you are using. It seems you are using GProlog. It will output yes when the query succeeds and there are no choice points left (no other possible solutions).

And it will answer true when the query succeeds but there are still other possible solutions to be checked.

于 2021-02-08T18:43:10.830 回答