Counting occurrences in list
问题 I'm trying to create a rule that counts the number of occurrences of a certain element in a given list, what I've tried so far does not seem to work the way I expect: The first argument here should be the list, the second one the element we are looking for, and the last one the number of occurrences: %empty list should always return 0 occurences count([],E,0) :- true. %if our head is what we are looking for, count count([E|T],E,N) :- count(T,E,N-1). %otherwise, do not count count([H|T],E,N) :