Counts the occurrences of an element in a list - back to content

 		Occurrences on the superficial level
        	?- count(a,[a,b,c,[a,c],a],R).
        	R = 2
         	We can also generate a list with N identical elements
        	?- count(a,X,10).
        	X = [a,a,a,a,a,a,a,a,a,a]
count(_,[],0). count(A,[A|L],N):- !,count(A,L,N1),N is N1+1. count(A,[_|L],N):- count(A,L,N).
Occurrences of an atom in a list on all levels ?- countt(a,[[[a],[c]],[c,a]],R). R = 2 ?- countt(a,[[[a],[b]],[c,a]],2). true. ?- countt(X,[a,b,c,[a,b,c,[a]]],3). X = a
countt(_,[],0). countt(A,[A|L],N):- !,countt(A,L,N1),N is N1+1. countt(A,[B|L],N):- atom(B),countt(A,L,N),!. countt(A,[B|L],N):- countt(A,B,N1),countt(A,L,N2),N is N1+N2.