本文介绍了为什么 SWI-Prolog 只给我第一个答案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Prolog 的新手.我只是尝试简单的例子来学习.我有这个 .pl
文件,其中包含以下几行:
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 .
不是应该给出满足关系parent
的所有组合吗?
Isn't it supposed to give all the combinations that satisfy the relation parent
?
有人知道问题出在哪里吗?
Do anyone have idea what the problem is?
推荐答案
在显示第一个结果后不要按 Enter,而是使用空格键
don't hit enter after your first results shows, use spacebar instead
[Enter]
即使回溯尚未完成也停止执行[Spacebar]
或[;]
继续从上一个结果回溯到下一个结果或false
如果没有其他结果离开了.
[Enter]
stops execution even if the backtracking is not completed yet[Spacebar]
or[;]
continues with backtracking from your last result to the next result orfalse
if there are no other results left.
这篇关于为什么 SWI-Prolog 只给我第一个答案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!