>Hi Peter,
>
>I was looking for an efficient way of doing this. Because if I'm doing a very simple recursion in foxpro I get an error message : insufficient stack space.
>
>Just doing the following, which represents an annuity:
>
>? aa(75)
>
>FUNCTION aa(n)
>
>IF n = 0 THEN
> RETURN 0
>ENDIF
>
>RETURN 1 + 1/(1+0.04)*aa(n-1)
>ENDFUNC
>
>Maybe recursion is not the way to do these things in foxpro? In c# I can do it w/o any problem.
>
>
this is a bug.
the implementation of the stack counter is not relative to "nesting calls"
but at the "nesting expression and calls";
then nesting can fail with 66 levels.
Another bug exist with Stack error and ON ERROR or Error() methods,
when the stack of the calls is exhausted these they cannot have called,
and the management of the error is managed by VFP
( VFP it has to reserve themselves at least a level
to be able to manage ON ERROR or Error());
of course TRY ENDTRY doesn't suffer from this problem
because before entering in CATCH VFP it empties the stack.
Then, before VFP9 the stack error cannot to be managed with ON ERROR or Error().
use aa2 way ( invert factors )
CLEAR
ON ERROR outError()
? aa(63)
? aa(64)
? aa2(63)
? aa2(125)
? aa2(126)
FUNCTION aa(n)
DEBUGOUT PROGRAM(-1)
RETURN IIF(n > 0,1 + 1/(1+0.04) * aa(n-1),0)
ENDFUNC
FUNCTION aa2(n)
RETURN IIF(n > 0,1 + aa2(n-1) * 1/(1+0.04),0)
ENDFUNC
PROCEDURE outError
? MESSAGE()
RETURN TO MASTER
on VFP9 you can put a STACKSIZE in config for implement a 32000-64000 stack
( better verifying it before putting it in production )