Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does SWI-Prolog only give me the first answer?

I'm new to Prolog. I'm just trying simple examples to learn. I have this .pl file with these lines:

parent(pam,bob).
parent(tom,bob).
parent(tom,lio).
parent(bob,ann).
parent(bob,pat).
parent(pat,jim).

After consulting and testing, it only shows the first answer. For example:

5 ?- parent(X,Y).
X = pam,
Y = bob .

Isn't it supposed to give all the combinations that satisfy the relation parent?

Do anyone have idea what the problem is?

like image 863
Sahar Alsadah Avatar asked Dec 25 '15 13:12

Sahar Alsadah


People also ask

How do you ask a question in Prolog?

In making a query you are asking Prolog whether it can prove that your query is true. If so, it answers "yes" and displays any variable bindings that it made in coming up with the answer. If it fails to prove the query true, it answers "No". Whenever you run the Prolog interpreter, it will prompt you with ?-.

What does no mean in Prolog?

At page 7 of the intro to the language they made the assertion : "In Prolog the answer no is used to mean nothing unifies with the question. It is important to remember that no is not the same as false".


1 Answers

don't hit enter after your first results shows, use spacebar instead

  • [Enter] stops execution even if the backtracking is not completed yet
  • [Spacebar] or [;] continues with backtracking from your last result to the next result or false if there are no other results left.
like image 145
Sam Segers Avatar answered Oct 19 '22 20:10

Sam Segers