Let's look at the rules first
num(0). num(X) :- num(X1), X is X1 + 1.
the predicate num(Y) will be immediately valid for Y = 0 .
Thus, the rule
fact(X) :- num(Y), fact(Y,X).
can be simplified as
fact(X) :- fact(0,X).
which will find a match for fact(0,1) . For X = 6 , what happens instead, since no rule defines a predicate for fact(0,6) , the search starts with fact(-1,V1) , and then with fact(-2,V2) , etc. .... until a match for fact(-value, Var) , where Var will be found as the local result.
This cannot be, and an infinite loop consumes the entire stack until an error is raised.
Ring Ø
source share