我已经开始学习 Prolog,我想用 findall/3 获取玩家的对手列表。在概括中,我只想将实际上是玩家的对手添加到列表中,除了我自己要求的玩家。我该如何制定这个例外?我知道否定是失败的概念,但我不确定我是否以及如何在这里需要它。
player(irina).
player(anton).
player(michael).
opponent(irina, anton).
opponent(irina, maria).
opponent(irina, michael).
% Only opponents who are also players should be added to the list,
% except the player of interest itself
opponent(X, Y) :- X \= Y, player(Y).
% the query
?- findall(O, opponent(irina,O) , OpponentList).
% the result
% only the first three results from the facts,
% the results from the rule, a second entry of
% anton and michael are missing.
OpponentList = [anton, maria, michael].
我实际上预计,该决议将按如下方式工作:
opponent(irina, irina) :- irina \= irina, player(irina).
% false true
% false
% false, hence not added to the list
opponent(irina, anton) :- irina \= anton, player(anton).
% true true
% true
% true, hence added to the list
我错过了什么?提前谢谢了!