列出订单敏感度

时间:2011-01-03 16:11:00

标签: prolog

鉴于事实

likes([apples, oranges], john).

我该怎么查询

 likes([apples, oranges], Who).

likes([oranges, apples], Who).

得到相同的结果?

2 个答案:

答案 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).