Natural number in SWI-prolog & recursive procedure
I have the next procedure for natural number开发者_如何学JAVA is SWI-prolog:
natural_number(0).
natural_number(s(X)) :- natural_number(X).
Now I want to do a recursive call, that stop when we arrive to 0.
My natural number is represented by - s(0)=0, s(s(0))=1, s(s(s(0)))=2, etc
So I define:
recommend(A, B, natural_number(0)) :-
dosomeFINITEfunction (a,b).
recommend(a,b,mynumber):-
dosomeFINITEfunction(a,b),
recommend (a,b, natural_number(mynumber)).
and call with: 3,5,s(0).
But it gives me the error: out of local stack
.
What is the problem? Thank you.
natural_number(s(0), 0).
natural_number(s(s(X)), N) :- natural_number(s(X), S), N is S + 1.
精彩评论