I'm trying to count atoms in a list. I can count all the atoms but I can't count a specific atom. I know there's something wrong with my code but I'm not sure how to fix it.
This works to count all the atoms in a list (the E (element) is irrelevant here):
count_atoms(_,[],0).
count_atoms(E,[H|T],R):- number(H), count_atoms(E,T,R1),R is R1,!.
count_atoms(E,[H|T],R):- var(H), count_atoms(E,T,R1),R is R1,!.
count_atoms(E,[H|T],R):- atom(H), count_atoms(E,T,R1),R is R1+1,!.
But this doesn't work to find the E (element) in the list:
count_atoms(_,[],0).
count_atoms(E,[H|T],R):- number(H), count_atoms(E,T,R1),R is R1,!.
count_atoms(E,[H|T],R):- var(H), count_atoms(E,T,R1),R is R1,!.
count_atoms(E,[H|T],R):- atom(H), E==H, count_atoms(E,T,R1),R is R1+1,!.
The result I get each time is just false.
Does anyone know what I'm doing wrong?