When does Prolog prompts 'yes' and when does it says 'true'

393 Views Asked by At

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'.

2

There are 2 best solutions below

3
gusbro On BEST ANSWER

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.

1
David Tonhofer On

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.