I'm looking for a clever way to identify recursive calls (so I can count them accurately in my sorting app I've been working on).  Right now, I am basically doing a stack trace in Java, and identifying all of the python function calls with in it, and then figuring out whenever there is a recursive call by seeing if the same function appears multiple times within the stack:

    String getPyFunc() {
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        List<String> funcNames = new ArrayList<String>();
        for (int i = 0; i < stackTrace.length; i++) {
            if (stackTrace[i].getMethodName().equals("call_function")) {
                String funcName = stackTrace[i - 1].getMethodName();
                funcName = funcName.substring(0, funcName.indexOf('$'));

                funcNames.add(funcName);
            }
        }

        if (!getFuncStack().isEmpty()
                && getFuncStack().size() != funcNames.size()
                && getFuncStack().get(0).equals(funcNames.get(0))) {
            log.finest("*** Recursion Identified ***");
            incrRecurses();
        }

        setFuncStack(funcNames);

        return getFuncStack().get(0);
    }

But what I am wandering is if there is a better way, where upon having a function called, the system can properly identify that it is a recursive call at execution. Does anyone have any suggestions?




--
"I'm not responcabel fer my computer's spleling errnors" - Xlorep DarkHelm
Website: http://darkhelm.org