I have implemented a factorial function in Java in the Eclipse IDE.
public class Utilities {
public static int factorial(int n) {
int result;
if (n <= 1) // base case
return 1;
else {
result = (n * factorial(n - 1));
return result;
}
}
}
In the display in Eclipse, I inspect Utilities.factorial(6)
. However, I get this error.
Utilities.factorial(6);
Evaluation failed. Reason(s):
Cannot perform nested evaluations.
Why does the display not support recursive calls? Is that the problem?
To return the answer, it must evaluate the expression, to do that it must evaluate the inner expression, to do that it must evaluate the inner expression, to do that it must evaluate the inner expression.
Generally when a debugger blows the stack (too many nested stack frames) people submit bugs to the development team that writes the debugger. They fix the problem, by the only means known at this time: No recursion.
If you could evaluate how deep the stack needs to go without evaluating the expression in a nested manner, for any recursive expression; there's a shiny Fields Medal waiting for you (and probably a University ready to build a new building in your name). This problem is related to the Halting Problem, and unfortunately, with our computing model, it is known that the Halting Problem is unsolvable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With