あるリストから別のリストへの一致数をカウントするこの述語を作成しようとしていますが、実行するたびに、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