Improvements in Programming Languages

Started by Charles Pegge, May 12, 2007, 10:38:30 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge

Okay, you need to set up new local variables/arguments every time the procedure is called. In your example, you will have a maximum of 6 sets of x, radius and level. These sets could be stored on a heap or stack as long as they are isolated from each other, and get released when exiting the procedure. This is what you need in addition to the stack for return addresses.

Zlatko Vid

thanks Charles
I never used heap so i must use array as stack
     'INITIAL CALL
     //push_to_stack
       stk[1] = x
       stk[2] = y
    //first recursive call
       stk[3] = x
       stk[4] = y -> topOfStack = 4

Is above code right?

Charles Pegge

Yes, you can do this for all functions. Often you get indirect recursion where functionA calls functionB which then calls functionA again. So you need to ensure that each instance of a function call has its own local variables.