Recursion is not reliable

From Liberty BASIC Family
Jump to navigation Jump to search

Description

Recursion in the debugger is fine. After creating an application it is NOT. The example below generates an "outside of collection bounds"-error.

Example code to demonstrate the bug.

    pol$="*(/(v(x),v(x)),v(x))"
    print "here it is: ";maakVeeltermUitPolish$(pol$)
    wait

function maakVeeltermUitPolish$(pol$)
    print "IN pol$=["+pol$+"]"
    c1$=left$(pol$,1)

    select case c1$
        case "/","*"
            dummy = getArgUitPolish(pol$,argpol1$,argpol2$)
            arg1$ = maakVeeltermUitPolish$(argpol1$)
            arg2$ = maakVeeltermUitPolish$(argpol2$)
            maakVeeltermUitPolish$ = arg1$ + " "+c1$+" "+arg2$
        case "v"
            dummy = getArgUitPolish(pol$,argpol1$,argpol2$)
            maakVeeltermUitPolish$ = argpol1$
    end select

    print "UIT pol$=["+pol$+"] met "+maakVeeltermUitPolish$
end function

function getArgUitPolish(pol$, byref arg1pol$,byref arg2pol$)
    c1$=mid$(pol$,1,1)

    select case c1$
        case "/"
            arg1pol$ = "v(x)"
            arg2pol$ = "v(x)"
        case "*"
            arg1pol$ = "/(v(x),v(x))"
            arg2pol$ = "v(x)"
        case "v"
            arg1pol$ = "x"
            arg2pol$ = ""
    end select
end function

Example code to work around the bug.

'code to work around the bug goes here