So I'm trying to create a method that determines the number of Ns in a list. I've been experimenting for an hour or so now and can't seem to get something solid. As of now, what I have returns 0. I think it might have something to do with my basecase, but I can't seem to figure it out. Logical programming such as prolog is a new horizon for me so any help would be great.
% base case returns 0 occurrences for empty list
numN(_,[],0).
numN(N,[Y | T], A) :- N == Y, numN(N,T,A2), A is A2+1.
numN(N, [Y | T], A) :- Y \= N, numN(N,T,A).
?- numN(X, [a,X,l,g,X], N).
N = 3.
when it should be 2. When I change the basecase to -1, then it returns the correct value.