in reply to Re^12: Continuations in Perl - Returning to an arbitrary level up the call stack
in thread Continuations in Perl - Returning to an arbitrary level up the call stack
And this is cheat again. 'goto' executed 4 times in 1st test, and 7 times in last test. You can achieve same if replace 'goto' with return, there won't be 'goto' in this code at all then (i.e. you rewrited this one particular case with plain recursion, without jumping frames)
And by the way, just in case if you pretend that it's always best to work that way, here is your posting where you explain to another monk, that it's not http://www.perlmonks.org/?node_id=1034169
For instance, when designing a recursion to search a graph it's sometimes desirable to stop immediately after the goal is reached.Also, this your cite explains everything
goto always jumps to the last TARGET -label in the call-stack andSo,
1 LABEL in source code can "remember" 1 stackframe.
and1 with_return statement in source code can "remember" N stackframes.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^14: Continuations in Perl - Returning to an arbitrary level up the call stack
by LanX (Saint) on May 20, 2013 at 12:01 UTC | |
by derby (Abbot) on May 20, 2013 at 12:13 UTC | |
by LanX (Saint) on May 20, 2013 at 12:15 UTC |