Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the display in Eclipse not support recursive functions in Java?

Tags:

java

eclipse

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?

like image 566
John Hoffman Avatar asked May 15 '12 19:05

John Hoffman


1 Answers

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.

like image 86
Edwin Buck Avatar answered Oct 12 '22 04:10

Edwin Buck