Also, this causes a linear scan of your code, so your jump will be slower (in the worst case) if your code base is larger.
That's just a bit misleading. If I didn't know how it really works, I'd take it to mean that it starts at the beginning of your program and scans the whole thing for the label. What it actually does is multiple linear scans from the innermost dynamic scope to the outermost dynamic scope. Since most gotos are local, the operation is usually relatively fast regardless of the code base size. But you did say "in the worst case", so I can't quibble about that. It's just the implication that there is only one linear scan of all the code.

And in fact, none of the individual scans are quite "linear" either. More like "cyclical". In a given dynamic scope, it always starts scanning forward first, and when it hits the end of the scope, it starts back at the beginning until it comes back to the place it started. Not only does this optimize for the fact that most gotos go forward rather than backward, but it also naturally cuts out of the loop any inner scope we already searched without an extra test.

That doesn't stop it from being bizarre though. And it will bite you hard if you misspell the label. Plus I don't know if Perl 6 will support goto EXPR, because it's a lot of hard work, and you have to be a crazy megalomaniac to do it. (I'd give examples of megalomaniacs, but I'm not exempt from Godwin's Law. Where do you apply for that?)


In reply to Re: Re: Re: Re: Duff's Device by TimToady
in thread Duff's Device by davido

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.