12

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?

3
  • 4
    don't hit enter after your first results shows, use spacebar instead
    – Sam Segers
    Commented Dec 25, 2015 at 13:26
  • perfect. Thanx for the help. Commented Dec 25, 2015 at 13:27
  • 2
    I've added this as an answer since I've got the feeling you are not the only one running into this.
    – Sam Segers
    Commented Dec 25, 2015 at 13:28

1 Answer 1

16

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.
3
  • 1
    Can you explain what the difference between space and enter does for future readers, too?
    – Chris Haas
    Commented Dec 25, 2015 at 13:54
  • I thought that was already clear, but if not, I hope this will do. Thanks.
    – Sam Segers
    Commented Dec 25, 2015 at 14:20
  • Thanks for the answer. But it doesn't say 'false' when no answers left. Display each result for every ';' and then goes to ?-. I'm trying on SWI-Prolog 8.2.4. Commented May 14, 2021 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.