elem([],0).
elem([H|T],R):-atomic(H),elem(T,R1),R1 is R+1.
elem([H|T],R):-elem(H,R1),elem(T,R2),R is R1+R2.
This is my code and after I searched the answer to my problem on this site, I didn’t find a good one. The error is : ?- elem([1,[2],3,4],R).
ERROR: is/2: Arguments are not sufficiently instantiated.
but it should be R = 3.
On the second line, you should have
instead of