And if we ignore the nature of the error, the solution is the same:
Instead of
> cString = cString + RECURSIVE(nLevel + 1)
use
c1 = RECURSIVE(nLevel + 1)
cString = cString + c1
> Here is a much shorter program which has the same behaviour. Try to alter the values of gnMaxLevel and gnReplicate. There seems to be a trade-off between them. If gnMaxLevel is higher, gnReplicate can be lower to show a failure.
>
> If you alter the line
>
>
> cString = cString + RECURSIVE(nLevel + 1)
>
>
> into
>
>
> cString = "" + cString + RECURSIVE(nLevel + 1)
>
>
> or
>
>
> cString = RECURSIVE(nLevel + 1) + cString
>
>
> no failure occurs.
>
> Benno.
>
>
>
> PUBLIC gnMaxLevel, gnReplicate
> gnMaxLevel = 6
> gnReplicate = 4
>
> RECURSIVE(0)
>
> FUNCTION RECURSIVE()
> LPARAMETERS nLevel
> LOCAL nLen1, nLen2, cString, cTest, cTest2
>
> IF nLevel < gnMaxLevel
> cString = REPLICATE("+", gnReplicate * 2 ^ (gnMaxLevel - nLevel - 1))
>
> nLen1 = LEN(cString)
> cString = cString + RECURSIVE(nLevel + 1)
> nLen2 = LEN(cString)
>
> IF nLen2 < nLen1
> ? "Failure at level: ", nLevel
> ELSE
> ? "OK at level: ", nLevel
> ENDIF
> ELSE
> cString = REPLICATE("-", gnReplicate)
> ENDIF
>
> RETURN cString
> ENDFUNC
>