我正在尝试在我的序言程序中编写一条规则,以确定某人是否是其他人的兄弟。
例如,如果我输入brother_of(chris, X) 它将返回christy,因为chris 是christy 的兄弟。但是,当我输入这个时,我得到一个存在异常。我已经包含了涵盖所有内容的事实,但也许这是我的规则定义中的问题?代码如下。
/* Facts */
female(ella).
female(jodi).
female(sonya).
female(jane).
female(christy).
female(mary).
male(arnold).
male(chris).
male(louis).
male(mark).
father(arnold).
father(louis).
father(mark).
mother(ella).
mother(jodi).
mother(jane).
mother(mary).
father_of(arnold, chris). /* arnold is the father of chris */
father_of(arnold, christy).
father_of(louis, mark).
father_of(mark, arnold).
mother_of(mary, chris).
mother_of(mary, christy).
mother_of(jane, arnold).
mother_of(ella, sonya).
mother_of(jodi, ella).
mother_of(jodi, mark).
/* Rules */
brother_of(X, Y) :-
male(X),
((father_of(Z, X), father_of(Z, Y));
(mother_of(W, X), mother_of(W, Y))),
X =\= Y.