**FACTS**
player(milan,[seedorf,zambrotta,gattuso]).
player(inter,[seedorf,ronaldo,zambrotta]).
player(realmadrid,[seedorf,zidane,ronaldo]).
我想创建一个谓词:
find (TEAM, PLAYERS)
如果我的目标是find(X,Y),它将返回团队列表 X 和球员列表 Y,没有任何重复...如下所示:
X=[milan], Y=[seedorf,zambrotta,gattuso];
X=[inter], Y=[seedorf,ronaldo,zambrotta];
X=[realmadrid], Y=[seedorf,zidane,ronaldo];
X=[milan,inter] Y=[seedorf,zambrotta];
X=[milan,realmadri] Y=[seedorf];
...
X=[milan,inter,realmadrid] Y=[seedorf];
...
我尝试这样做,但它给出“错误:超出本地堆栈”,如果我不使用 remove_dups 谓词,团队列表,“X”,将会有重复并且程序无法停止......继续像 X =[milan,milan,milan,milan,inter] .... 我该如何更正此代码。?:
find([X], Y) :- player(X1, Y),remove_dups(X1,X).
find([X|Xs], Y) :- player(X1, Y0),find(Xs, Y3), intersection(Y0, Y3, Y),remove_dups(X1,X).
remove_dups([],[]).
remove_dups([First|Rest],NewRest):-member(First, Rest),remove_dups(Rest, NewRest).
remove_dups([First|Rest],[First|NewRest]):-not(member(First, Rest)),remove_dups(Rest, NewRest).
非常感谢...