4
$\begingroup$

Consider the following code segment:

f[x_]:=Module[{y},
   Print[counter++];
   Return[f[x+1]];
];
$RecursionLimit=20;
counter=0;
f[0]

The function terminates after only 8 recursions. Now, delete y from the function:

g[x_]:=Module[{},
   Print[counter++];
   Return[g[x+1]];
];
$RecursionLimit=20;
counter=0;
g[0]

and termination is achieved after 17 recursions. What is the resason for this discrepancy and even in the second case, where are the missing recusions?

My Mathematica version is 10.0.2.0.

$\endgroup$
2
  • $\begingroup$ For what it's worth, in version 9, the second one also terminates after 8 recursions. $\endgroup$ Commented May 13, 2016 at 0:24
  • $\begingroup$ Can I give this question a bug tag? $\endgroup$ Commented May 15, 2016 at 16:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.