我在理解为什么我的prolog代码根据我的规则的顺序做了一些事情时遇到了一些麻烦.
这是我的数据库:
parent(tom, bob).
parent(tom, liz).
parent(mary, bob).
parent(mary, liz).
male(tom).
male(bob).
female(mary).
female(liz).
Run Code Online (Sandbox Code Playgroud)
以下是规则:
%difference(X, Y) ==> Predicate to check if two people X and Y are not the same person.
difference(X, Y) :- \==(X, Y).
father(X, Y) :- male(X), parent(X, Y), difference(X, Y).
mother(X, Y) :- female(X), parent(X, Y), difference(X, Y).
sibling(X, Y) :-
difference(X, Y),
mother(M, X), mother(M, Y),
father(F, X), father(F, Y).
Run Code Online (Sandbox Code Playgroud)
问题是,当我这样做时,
?- sibling(bob, X).
Run Code Online (Sandbox Code Playgroud)
我明白了
X = bob ;
X = liz ;
false. …Run Code Online (Sandbox Code Playgroud)