TL;DR:如果你使用 subtract/3 http://www.swi-prolog.org/pldoc/doc_for?object=subtract/3,你的代码可能会丢失逻辑纯粹性 /questions/tagged/logical-purity.
person(john).
person(erik).
allExceptSpider(Spider, T) :-
setof(X, person(X), S),
subtract(S, [Spider], T).
保持纯洁!如何?使用list_item_subtracted/3 https://stackoverflow.com/a/29432897/4609915like so:
allExceptSpiderNU(Spider, T) :-
setof(X, person(X), S),
list_item_subtracted(S, Spider, T).
头对头查询示例:
?- allExceptSpider(Z, Q).
Q = [erik], Z = john.
?- allExceptSpiderNU(Z,Q).
Q = [ erik] , Z=john
; Q = [john ], Z=erik
; Q = [john,erik], dif(Z,erik), dif(Z,john).