Returning from a multiple stacked call at once

jak nospam at please.ty
Tue Dec 15 04:41:24 EST 2020


Il 12/12/2020 18:20, Dieter Maurer ha scritto:
> ast wrote at 2020-12-12 07:39 +0100:
>> In case a function recursively calls itself many times,
>> is there a way to return a data immediately without
>> unstacking all functions ?
> 
> Python does not have "long jump"s (out of many functions, many loop
> incarnations).
> In some cases, you can use exceptions to emulate "long jump"s.
> 

I don't know what you mean by 'emulating' because using the exception 
handler you simply defer unstacking to it. The real problem is that if 
you write a function that ends by calling itself and does not take 
advantage of the branch of code following the recursive call, then it is 
a wrong way to use a recursive function which should be replaced with a 
simple one containing a loop where you can insert a break statement 
wherever you like. IMHO

Greetings.


More information about the Python-list mailing list