In my frenzy to chase down novel (to me) ideas, I neglected to comment on L~R's main point, which I'll immodestly restate as:
What if Perl had a language construct for "Do this only once"?
(We can argue about whether this should be "once" or "N times".)

The core idea is once the test fails, it's removed from the optree.

What would we use for syntax?

once (/foo/) { print "I've seen foo\n"; }
or more often
once (my $i;/foo/;$i++ < 42) { print "I've seen foo $i times\n"; }
Would it be useful? It seems it's only merit is in speeding up tight loops, where even checking a boolean is noticeable.

Would it cause bugs? Yes, definitely. There would be a cargo cult of "Use once to optimize conditionals", when very few situations actually benefit from it.

Is it more convenient than anything existing? Yes, indeed. I have yet to see anything that approaches the efficiency of once.

I'll be interested in seeing if this idea catches fire, implemented, and how many bugs it generates.

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Re: Doing "it" only once by QM
in thread Doing "it" only once by Limbic~Region

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.