我正在尝试创建这个谓词来计算从一个列表到另一个列表的匹配数,但是每当我运行它时,我都会不断收到关于 X 和 Y 值未正确实例化的错误。有人知道如何解决这个问题吗?
:- dynamic listCount/1.
listCount(0).
intersection([],_,_).
intersection([H|T], CheckingList, _):-
member(H,CheckingList), %checks if it's within the list
deleteFromList(CheckingList, H, NewList), %deletes all occurrences form the list
listCount(X), %retrieves the persistent value
retractall(listcount(_)),
Y is X + 1, &increments the value
assert(listcount(Y)),
intersection(T, NewList,Y). %recurses on the remaining list