【发布时间】:2013-05-02 08:38:01
【问题描述】:
我遇到了以下问题:
定义了以下事实和谓词:
father(avr, yit).
male(avr).
married(avr, sara).
father(yit, yaak).
married(rivka, yit).
father(yaak, yosef).
mother(rachel, yosef).
father(yaak, levi).
mother(leaa, levi).
mother(zilpa, gad).
father(yaak, dan).
mother(bilhaa, dan).
father(yosef, menashe).
father(yosef, ephraim).
are_married(X,Y) :- married(X,Y).
are_married(X,Y) :- married(Y,X).
我定义了以下谓词:
married(X,Y) :- mother(X,Z) , father(Y,Z).
mother(X) :- are_married(X,Y) , father(Y,_).
现在的问题是,妈妈是由婚姻来定义的,而婚姻是由做妈妈来定义的——结果是死循环,程序崩溃了。
如何防止无限循环?有没有办法告诉谓词不要使用不同的谓词?
【问题讨论】:
-
不,只是使用不同的名称。这是最近被问到和回答的,只是browse here 通过最近的一些问题,here 通过答案。
标签: recursion prolog infinite-loop