Generarl programming question.

jonas.thornvall at jonas.thornvall at
Sat Apr 11 17:22:44 CEST 2015

Den lördag 11 april 2015 kl. 17:16:09 UTC+2 skrev Chris Angelico:
> On Sun, Apr 12, 2015 at 1:00 AM,  <jonas.thornvall at> wrote:
> > If two functions crossreference eachother back and forth what happen with the local variables.
> >
> > Will there be a new instance of function holding the variables or do they get messed up?
> You mean if one function calls another, and that function calls the
> first? That's called "mutual recursion":
> def func1(x):
>     if x % 2: return x + 1
>     return func2(x - 2)
> def func2(x):
>     if x % 3: return x + 2
>     return func1(x - 3)
> The 'x' inside each function is completely separate, no matter how
> many times they get called. They're usually stored on something called
> a "call stack" - you put another sheet of paper on top of the stack
> every time you call a function, local variables are all written on
> that paper, and when you return from a function, you discard the top
> sheet and see what's underneath.
> For more information, search the web for the key terms in the above
> description, particularly the ones I put in quotes.
> If this isn't what you're talking about, the best way to clarify your
> question is probably to post a simple (even stupidly trivial, like the
> one above) example, and ask a question about that code. Someone'll
> doubtless help out!
> ChrisA

Thanks i was worried, i try to make a generic base choice algorithm that should work for anybase, and i just realised that the bignumb add would need to call the bignumb subtraction and viceversa. I thought there may be instances but i was not sure. 

But I have a feeling the code will be hard to debug.

More information about the Python-list mailing list