Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-20 03:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found