I'm new to prolog I'm trying to write a predicate which counts the following: the predicates name is s2int when given:
- s2int(0,Y) it shoud "return" Y=0.
- s2int(s(0),Y) => Y=1.
- s2int(s(s(0)),Y) => Y=2.
- s2int(S(s(s(0))),Y) => Y=3.
and so on.. here is what i tried to write(very poorly), at first i tried this code:
s2intAux(0,Y).
s2intAux(X,Y):- X = s(Z) ,Y1 is Y+1, s2intAux(Z,Y1).
but whenever i try to run it by typing s2intAux(s(0),Y) i get an error saying :"ERROR: is/2: Arguments are not sufficiently instantiated" i get that error well because Y is undefined. then i tried this one:
s2intAux(0,Y).
s2intAux(X,Y):- X = s(Z) ,Y1 is Y+1, s2intAux(Z,Y1).
s2int(X,Y):- Y1 is 0, s2intA(X,Y1).
(i tried to start Y with the value zero but this one didn't work at all) I've been stuck for a couple of hours now which is why I'm turning to you guys, please help! thank you.