Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^7: Who's a thief? (No memory growth with magic goto)

by BrowserUk (Pope)
on Jan 14, 2005 at 20:54 UTC ( #422382=note: print w/replies, xml ) Need Help??


in reply to Re^6: Who's a thief? (No memory growth with magic goto)
in thread Who's a thief? -- the follow up

From perlsyn:

The goto-&NAME form is highly magical, and substitutes a call to the named subroutine for the currently running subroutine

Limbic~Region's post referenced a post by TimToady which will give the real skinny of how it works, but it does avoid the stack growth at the penalty of requiring the programmer to arrange for the algorithm to be tail-recursive.

You can use closures to provide yourself with one or more "stacks" if that is required. By controlling what gets stacked and when, even some non-tail recursive algorithms can benefit from reduced memory consumption and greater speed. It is especially useful for mutually recursive algorithms that need to share intermediate results.

That takes some effort, but if you have an inherently recursive algorithm that lends itself to that process, and a need for speed, then it can be worth it.


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
  • Comment on Re^7: Who's a thief? (No memory growth with magic goto)

Replies are listed 'Best First'.
Re^8: Who's a thief? (No memory growth with magic goto)
by dragonchild (Archbishop) on Jan 14, 2005 at 21:36 UTC
    I've seen goto ⊂ ... I've never seen goto \⊂, which is what you did. Is there a difference?

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Sorry, I didn't even notice that I typed \& through force of habit. And no, it appears to make no difference whatsoever.

      Perl DWIMs again :)


      Examine what is said, not who speaks.
      Silence betokens consent.
      Love the truth but pardon error.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://422382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2019-11-18 01:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (87 votes). Check out past polls.

    Notices?