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

我怕爱的太早我们不能终老 提交于 2019-12-19 05:59:24

问题


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?


回答1:


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.


来源:https://stackoverflow.com/questions/34463248/why-does-swi-prolog-only-give-me-the-first-answer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!