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?
or more oftenonce (/foo/) { print "I've seen foo\n"; }
Would it be useful? It seems it's only merit is in speeding up tight loops, where even checking a boolean is noticeable.once (my $i;/foo/;$i++ < 42) { print "I've seen foo $i times\n"; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |