Ask Your Question

Revision history [back]

Your error is not due to recursion. The following example (slightly simplified with respect to yours) produces the same error :

def f(n) :
    def retfunc(x) : 
        if n==0:
            return 1
        return x*f(3)
    return retfunc

w=f(9)
w(3)

The error is at x*f(3). f(3) is a function, not a number. I don't really understand what you are trying to do. Some kind of factorial ?

The following code does not produce the error :

def f(n) :
    def retfunc(x) : 
        if n==0:
            return 1
        return x*f(n-1)(3)
    return retfunc

w=f(9)
print w(3)

Note : f(n-1)(3)

Hope it helps

Laurent