This question has been asked quite a lot (for instance, here) but I could not understand why it's happening and how to fix it.
I want to make a list Z
and count its elements. This is my code:
Z = [a,b,c,d,e].
listlength([],0).
listlength([Head|Tail],Count):-
listlength(Tail,PartialCount),
Count is PartialCount + 1 .
But I get the following error (and warnings):
ex3.pl:1: Warning: Singleton variables: [Z]
ex3.pl:1: ERROR: No permission to modify static procedure `(=)/2'
ex3.pl:5: Warning: Singleton variables: [Head]
ex3.pl:5: Warning: Singleton variables: [Head]
I do not understand how I can fix it, and I do not know how to define a list and test the listlength
rule. I'm using SWI-Prolog 7.6.4 x64.