Swi Prolog keeps track of recursion depth
Why does recursion depth start at 6 or 7 when tracing Prolog programs?
Example (taken from the form here ).
factorial(0, 1).
factorial(N, NFact) :-
N > 0,
Nminus1 is N - 1,
factorial(Nminus1, Nminus1Fact),
NFact is Nminus1Fact * N.
Allows you to trace factorial(3, X)
. Output:
Call: (7) factorial(3, _G284) ? creep*
Call: (8) 3>0 ? creep
Exit: (8) 3>0 ? creep
Call: (8) _L205 is 3-1 ? creep
etc. The first column ( Call, Exist
) is the ports, the third is the targets, and the second is the recursion depth. But why does it start at 7? (When I run the example on my machine, it starts at 6) Shouldn't it start at 1 or 0?
+3
source to share
No one has answered this question yet
Check out similar questions: