Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Recursion with foxpro
Message
De
16/01/2006 02:54:42
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01086981
Message ID:
01087062
Vues:
65
>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) && OK
? aa(64) && Fail

? aa2(63) && OK   Look that the output format change ( anothe bug )
? aa2(125) && OK
? aa2(126) && Fail and outError() cannot to be called ( bug )

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 )
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform