這是我的代碼:序言 - 添加從列表中的元素到另一個列表,不重複
students([], NameList).
students([Name1+Name2+_|MoreProjects], [Name1,Name2|NameList]) :-
not_member(Name1, NameList),
not_member(Name2, NameList),
students(MoreProjects, NameList).
students([Name1+Name2+_|MoreProjects], [Name1|NameList]) :-
not_member(Name1, NameList),
not(not_member(Name2, NameList)),
students(MoreProjects, NameList).
students([Name1+Name2+_|MoreProjects], [Name2|NameList]) :-
not(not_member(Name1, NameList)),
not_member(Name2, NameList),
students(MoreProjects, NameList).
students([Name1+Name2+_|MoreProjects], NameList) :-
not(not_member(Name1, NameList)),
not(not_member(Name2, NameList)),
students(MoreProjects, NameList).
not_member(_, []).
not_member(X, [Head|Tail]) :-
X \= Head,
not_member(X, Tail).
什麼它應該做的是檢查,如果名稱1或名稱2已經在綁定列表,並將其添加到結果。
運行這個合法查詢
students([ Dickens+Joyce+1,
Chekhov+Tolstoy+2,
Austen+Shakespeare+3,
Shirley+Byron+4
],
StudentList).
只是給了我假的。我應該如何調整我的編碼?