鉴于事实
likes([apples, oranges], john).
我该怎么查询
likes([apples, oranges], Who).
和
likes([oranges, apples], Who).
得到相同的结果?
答案 0 :(得分:3)
如果你不想排序,我会做那样的事情:
文件:
likes([apples, oranges], jo).
likes_find([],_).
likes_find([Head | Tail] , Who):-
likes(List1 , Who),
member(Head , List1),
likes_find(Tail ,Who).
测试:
?- likes_find([oranges,apples],X).
X = jo .
?- likes_find([oranges,apples,fail_here_plz],X).
false.
?- likes_find([oranges],X).
X = jo .
?- likes_find([oranges,apples],jo).
true .
?- likes_find([apples,oranges],jo).
true .
答案 1 :(得分:1)
如果在likes/2
中,第一个(列表)参数始终是手动排序且不包含重复,则使用
likes_list(Stuff,Person) :- sort(Stuff,Sorted), likes(Sorted,Person).