I am trying to right a predicate in Prolog that accepts an item, a list, and a number, and checks to see if the item is in the list that number of times. For example
count(7,[3,7],X).
would return X=1.
count(7,[3,7],1).
would return true
This is what I have so far
count_occur(A,[0|B],D).
count_occur(A,[A|C],D) :- count_occur(A,C,D1), D is D1+1.
count_occur(A,[B|C],D) :- count_occur(A,C,D).
I am very new to Prolog and really struggling to understand this programming paradigm.
What I am trying to do is to see if the first item in the list matches the passed-in value (A), if it does increment D and check again against the remainder of the list. This is how I would do it in lisp or another language anyway. Could really use some help, been at this for a while and it just isn't clicking for me.