in reply to Doing "it" only once
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Doing "it" only once
by diotalevi (Canon) on Sep 22, 2005 at 14:15 UTC | |
by Limbic~Region (Chancellor) on Sep 22, 2005 at 19:10 UTC | |
by QM (Parson) on Sep 22, 2005 at 19:41 UTC | |
|
Re^2: Doing "it" only once
by Anonymous Monk on Sep 22, 2005 at 15:35 UTC | |
by QM (Parson) on Sep 22, 2005 at 17:51 UTC | |
by Anonymous Monk on Sep 23, 2005 at 09:06 UTC | |
by QM (Parson) on Sep 23, 2005 at 12:07 UTC |