你可以做的是:
% initialize which way is safe
isSafe(left).
% predicates for truth and lie tellers
truthTeller(X) :- X.
lieTeller(X) :- \+ X.
wouldTheOtherSay(X) :- truthTeller(lieTeller(X)).
那么你只需要问:
?- willTheOtherSay(isSafe(left)).
这将永远是一个谎言,所以如果答案是yes,你应该正确,反之亦然。
编辑
这是另一个版本:
% initialize which way is safe
isSafe(left).
% initialize who is a truth-teller & who is a lie-teller
truthTeller(dean).
lieTeller(sean).
% a truth-teller would say Y is true if Y is true
% a lie-teller would say Y is true if Y is false
wouldSay(X,Y) :-
truthTeller(X),Y;
lieTeller(X),\+Y.
% a truth-teller would say the other would say Y is true if Y is false
% a lie-teller would lie and say the other would say Y is true if Y is false
wouldTheOtherSay(X,Y) :-
truthTeller(X),lieTeller(Z),wouldSay(Z,Y);
lieTeller(X),truthTeller(Z),wouldSay(Z,\+Y).
% this is so you don't get true then false -- we keep the first result
onceWouldTheOtherSay(X,Y) :- once(wouldTheOtherSay(X,Y)).
然后:
?- onceWouldTheOtherSay(sean,isSafe(left)).
?- onceWouldTheOtherSay(dean,isSafe(left)).
会给你no,和:
?- onceWouldTheOtherSay(sean,isSafe(right)).
?- onceWouldTheOtherSay(dean,isSafe(right)).
会给你yes。
尽管如此,lie*truth 等于 truth*lie 等于 lie,你应该反过来。