Closed p5pRT closed 11 years ago
I classified this as 'medium' (not high or critical)\, as it is obviously a corner case in the parser.
I had:
perl -E '
use P;
for ($_=3;$_-- >0;) { P "_=%s"\, $_ }'
_=2
_=1
_=0
---
Decided to try the post-fix notation:
perl -E '
use P;
P "_=%s"\, $_ for $_=3;$_-- >0; '
_=3
---
Warnings would have pointed out:
Useless use of numeric gt (>) in void context at -e line 1.
I tried it with parens:
perl -E ' use P; P "_=%s"\, $_ for ($_=3;$_-- >0;) ' syntax error at -e line 3\, near "3;" syntax error at -e line 3\, near ";) " Execution of -e aborted due to compilation errors.
(Note\, to reproduce this without P: perl -lE' print sprintf "_%s"\, $_ for $_=3;$_-- >0; '
- I generally prefer to save on typing)...
--- Now some said that in the postfix notation\, the for was interpreted as a synonym for "foreach".
As I was quoted on perlmonks:
From the Camel Book (4th Edition\, 2012\, page 142):
For historical reasons\, the foreach keyword is a synonym for the for keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation. We tend to prefer for because we are lazy and because it is more readable\, especially with the my. **** (Donât worryâPerl can easily distinguish for (@ARGV) from for ($i=0; $i\<$#ARGV; $i++) because the latter contains semicolons.) ***
----- The '****' are mine. Note that perl is supposed to be able to distinguish my usage of "for my $_=0; $_--\<0;[;]" due to the extra semicolons.
(I originally had a double semi at the end\, and figured that was clearly redundant)
Perl know's something is wrong in the warnings... it sees the incorrect syntax.
Even with parens\, when it really has the hint of semicolons in a for(;;)\, the Camel book claims it *should* know the difference...
I only gave this as high as a 'medium' because\, it so clearly goes against the wording of the 'camel'... though\, admittedly\, it is the first time i've run into this corner case (trying to make code "more brief" and more efficient" -- and read that entering a loop has a context overhead whereas the post-fix format of the loop did not). Dunno if it is true It's in the comments of Exporter.pm\, which I was trying to 'grok'\, chasing down an obscure bug...
I didn't know "for(;;)" was a lone exception to the post-fix notation\, and think\, given the camel book\, it's clearly an oversight in consistency.
Linda Walsh \perlbug\-followup@​perl\.org wrote:
Now some said that in the postfix notation\, the for was interpreted as a synonym for "foreach".
That doesn't match the Perl documentation; `perldoc perlsyn` has this to say about statement modifiers:
Any simple statement may optionally be followed by a SINGLE modifier\, just before the terminating semicolon (or block ending). The possible modifiers are:
if EXPR unless EXPR while EXPR until EXPR for LIST foreach LIST when EXPR
That doesn't include anything like "for (EXPR; EXPR; EXPR)".
From the Camel Book (4th Edition\, 2012\, page 142):
For historical reasons\, the foreach keyword is a synonym for the for keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation\. We tend to prefer for because we are lazy and because it is more readable\, especially with the my\. \*\*\*\* \(Donât worryâPerl can easily distinguish for \(@​ARGV\) from for \($i=0; $i\<$\#ARGV; $i\+\+\) because the latter contains semicolons\.\) \*\*\*
The Camel book isn't something that p5p has any control over.
I've had an (admittedly brief) look at Perl's documentation for "for" and "foreach"\, and I can't see anything which might be construed as suggesting that three-part "for" can be used as a statement modifier. If you can point to anything I've missed\, please let us know\, and we can clarify those parts of the documentation.
Thanks.
-- Aaron Crane ** http://aaroncrane.co.uk/
The RT System itself - Status changed from 'new' to 'open'
Linda Walsh (via RT) \perlbug\-followup@​perl\.org writes:
Decided to try the post-fix notation: perl -E ' use P; P "_=%s"\, $_ for $_=3;$_-- >0; ' _=3 --- Warnings would have pointed out: Useless use of numeric gt (>) in void context at -e line 1.
Note that L\<perlsyn/Statment Modifiers>Âč only lists "for LIST" and "foreach LIST".
The (EXPR; EXPR; EXPR) form is only listed in L\<perlsyn/Compound Statements>ÂČ.
[1] https://metacpan.org/module/perlsyn#Statement-Modifiers [2] https://metacpan.org/module/perlsyn#Compound-Statements
As I was quoted on perlmonks:
From the Camel Book (4th Edition\, 2012\, page 142):
For historical reasons\, the foreach keyword is a synonym for the for keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation\. We tend to prefer for because we are lazy and because it is more readable\, especially with the my\. \*\*\*\* \(Donât worryâPerl can easily distinguish for \(@​ARGV\) from for \($i=0; $i\<$\#ARGV; $i\+\+\) because the latter contains semicolons\.\) \*\*\*
Is this in a section on compound statements\, or about statement modifiers? They are not the same\, despite having similar (but not identical!) names and behavoiur.
-- "A disappointingly low fraction of the human race is\, at any given time\, on fire." - Stig Sandbeck Mathisen
On Fri\, Feb 1\, 2013 at 11:40 AM\, Aaron Crane \perl@​aaroncrane\.co\.uk wrote:
From the Camel Book (4th Edition\, 2012\, page 142):
For historical reasons\, the foreach keyword is a synonym for the for
keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation. We tend to prefer for because we are lazy and because it is more readable\, especially with the my. **** (Donât worryâPerl can easily distinguish for (@ARGV) from for ($i=0; $i\<$#ARGV; $i++) because the latter contains semicolons.) ***
The Camel book isn't something that p5p has any control over.
Nor is it entirely wrong. It is technically correct\, which\, as I was recently told\, is the best kind of correct.
Yes\, the keywords are synonymous\, and can be used interchangeably\, even as statement modifiers:
$ perl -E 'say foreach 1..3' 1 2 3 $
And yes\, Perl "can easily distinguish for (@ARGV) from for ($i=0; $i\<$#ARGV; $i++)"\, and does so\, even for statement modifiers. Quite distinct results:
$ perl -E 'say for (@ARGV)' 1 2 3 1 2 3 $ perl -E 'say for ($i=0; $i\<$#ARGV; $i++)' 1 2 3 syntax error at -e line 1\, near "0;" syntax error at -e line 1\, near "++) " Execution of -e aborted due to compilation errors. $
And no\, it does not say that the C\<\< for (EXPR; EXPR; EXPR) >> construct (or foreach equivalent) is accepted as a statement modifier.
Not technically\, anyway. ;-)
Eirik
@iabyn - Status changed from 'open' to 'rejected'
On Fri\, Feb 1\, 2013 at 3:15 AM\, Linda Walsh \perlbug\-followup@​perl\.orgwrote:
From the Camel Book (4th Edition\, 2012\, page 142):
For historical reasons\, the foreach keyword is a synonym for the for
keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation. We tend to prefer for because we are lazy and because it is more readable\, especially with the my. **** (Donât worryâPerl can easily distinguish for (@ARGV) from for ($i=0; $i\<$#ARGV; $i++) because the latter contains semicolons.) ***
The part outside the stars is correct. foo() for (1;2;3); and foo() foreach (1;2;3); are equivalent.
The part inside the stars is also correct. It's easy to distinguish for (@ARGC) from ($i=0; $i\<$#ARGV; $i++)
That passage makes no claim that Perl supports postfix C-style for loop. That passage makes no claim that Perl supports postfix C-style for loop. The bug is entirely yours.
- Eric
On Fri Feb 01 02:41:52 2013\, perl@aaroncrane.co.uk wrote:
Linda Walsh \perlbug\-followup@​perl\.org wrote:
Now some said that in the postfix notation\, the for was interpreted as a synonym for "foreach".
That doesn't match the Perl documentation; `perldoc perlsyn` has this to say about statement modifiers:
Any simple statement may optionally be followed by a SINGLE modifier\, just before the terminating semicolon (or block ending). The possible modifiers are:
if EXPR unless EXPR while EXPR until EXPR for LIST foreach LIST when EXPR
That doesn't include anything like "for (EXPR; EXPR; EXPR)".
From the Camel Book (4th Edition\, 2012\, page 142):
For historical reasons\, the foreach keyword is a synonym for the
for keyword\, so you can use for and foreach interchangeably\, whichever you think is more readable in a given situation. We tend to prefer for because we are lazy and because it is more readable\, especially with the my. **** (Donât worryâPerl can easily distinguish for (@ARGV) from for ($i=0; $i\<$#ARGV; $i++) because the latter contains semicolons.) ***
The Camel book isn't something that p5p has any control over.
I've had an (admittedly brief) look at Perl's documentation for "for" and "foreach"\, and I can't see anything which might be construed as suggesting that three-part "for" can be used as a statement modifier. If you can point to anything I've missed\, please let us know\, and we can clarify those parts of the documentation.
Thanks.
====================================================================
No wonder people close out my bugs claiming there is no response...
People need to get a clue... if my responses are being censored\, you can't expect reply unless I checked (as i did this time -- as I thought it odd I got no response nor notice that the bug had been closed.
-------- Original Message -------- Subject: Re: [perl #116605] perl parse not parsing post-position 'for(;;)' as camel claims Date: Fri\, 01 Feb 2013 07:00:25 -0800 From: Linda W \perl\-diddler@​tlinx\.org To: perlbug-followup@perl.org References: \RT\-Ticket\-116605@​perl\.org \5\.16\.1\_13583\_1359704903@​Ishtar\.sc\.tlinx\.org \rt\-3\.6\.HEAD\-27190\-1359706523\-1193\.116605\-75\-0@​perl\.org \CACmk\_tsRX=Ukz0WBx9qf=peK2\+\-\-1TETkc=rawm\-3r3e\-2o4yg@​mail\.gmail\.com \rt\-3\.6\.HEAD\-27190\-1359715312\-1576\.116605\-94\-0@​perl\.org
Aaron Crane via RT wrote:
Any simple statement may optionally be followed by a SINGLE modifier\, just before the terminating semicolon (or block ending). The possible modifiers are:
if EXPR unless EXPR while EXPR until EXPR for LIST foreach LIST when EXPR
What statements that control modifiers besides 'for' Cannot follow as post-fix operators?
More concern to me is 'regularity' in the language. I may very easily be overlooking the obvious\, but it seems like "for(;;)" stands alone as the single flow control statement that can't be used in post-fix form.
Someone read to me the what felt like an obvious statement -- that perl can tell the difference in the forms and doesn't confuse the for(;;) (with semicolons) with the for(LIST). So it made no sense that for(;;) (that perl would never confuse with for(LIST)\, wouldn't be supported as a special case.
Is there a special reason why it cannot or should not be supported the same as the other control statements and why a "special case" for it "not working" the way the rest do\, be adhered to? I really don't know -- honest... it just seems out of place\, like a wart....
;-)
perl-diddler@tlinx.org - Status changed from 'rejected' to 'open'
-------- Original Message -------- Subject: Re: [perl #116605] perl parse not parsing post-position 'for(;;)' as camel claims Date: Fri\, 01 Feb 2013 13:46:48 -0800 From: Linda W \perl\-diddler@​tlinx\.org To: perlbug-followup@perl.org References: \RT\-Ticket\-116605@​perl\.org \5\.16\.1\_13583\_1359704903@​Ishtar\.sc\.tlinx\.org \rt\-3\.6\.HEAD\-27190\-1359706523\-1193\.116605\-75\-0@​perl\.org \CALJW\-qGfgzTj0xzRGHAKg2qqhJgKjS\+SpR2gUO5uf2qGWhSL5w@​mail\.gmail\.com \rt\-3\.6\.HEAD\-27190\-1359743084\-1098\.116605\-94\-0@​perl\.org
On Fri Feb 01 10:24:44 2013\, ikegami@adaelis.com wrote:
That passage makes no claim that Perl supports postfix C-style for loop. That passage makes no claim that Perl supports postfix C-style for loop. The bug is entirely yours.
- Eric
Nor does it claim that it does not. It says not to worry about use of "for(;;)"\, as "Perl can easily distinguish" between the two usages.
That implies that "for(;;)"\, could be used in any place "foreach" can be used and for the user NOT to WORRY\, as Perl can easily distinguish between the two.
I asked what other start-of-flow control words besides for(;;) could not be used in a postfix manner. If "for(;;)" is the only one -- why? Since perl can parse it the same as any other\, why should it be the 1 control statement that it shouldn't parse -- just because you want to be able to point fingers at people\, post "LOL" comments (on PM)\, and tell people it is there bug?
How childish is that? I get kicked from the list for telling someone that those who don't change -- like the dinosaurs\, end up having problems (there was nothing personally attacking in my post\, Ricardo just didn't like being told the world was round: it was flat\, by original design\, and would be kept that way for compatibility with previous design. ;^/
It is a non-regularity in the language that doesn't need to be there. It would follow that if one thought all of the other flow-control words could be post-fixed\, then why not that one? I don't need "it's your bug" as a reason -- that's Certainly it is not rational\, technical nor compelling compelling reason why irregularities in the language shouldn't be fixed when possible (even though it is rather consistent with the reasoning[sic] why I was no longer allowed to post to the flock of believers...
That perl has so many exceptions works against it. It's a major reason why\, like python's founder\, Larry thought a complete overhaul was necessary -- because people wouldn't accept piecemeal improvements.
While the ability to "deprecate" bad design and features has improved\, grandfather logic has dominated the p5p list to the point that those pushing for change are eliminated from the list -- even when it is a something so trivial as regularizing the documentation!
On Sat Feb 02 18:30:18 2013\, LAWalsh wrote:
-------- Original Message -------- Subject: Re: [perl #116605] perl parse not parsing post-position 'for(;;)' as camel claims Date: Fri\, 01 Feb 2013 13:46:48 -0800 From: Linda W \perl\-diddler@​tlinx\.org To: perlbug-followup@perl.org References: \RT\-Ticket\-116605@​perl\.org \5\.16\.1\_13583\_1359704903@​Ishtar\.sc\.tlinx\.org \rt\-3\.6\.HEAD\-27190\-1359706523\-1193\.116605\-75\-0@​perl\.org \CALJW\-qGfgzTj0xzRGHAKg2qqhJgKjS\+SpR2gUO5uf2qGWhSL5w@​mail\.gmail\.com \rt\-3\.6\.HEAD\-27190\-1359743084\-1098\.116605\-94\-0@​perl\.org
On Fri Feb 01 10:24:44 2013\, ikegami@adaelis.com wrote:
That passage makes no claim that Perl supports postfix C-style for loop. That passage makes no claim that Perl supports postfix C-style for loop. The bug is entirely yours.
- Eric
Nor does it claim that it does not. It says not to worry about use of "for(;;)"\, as "Perl can easily distinguish" between the two usages.
That implies that "for\(;;\)"\, could be used in any place
"foreach" can be used and for the user NOT to WORRY\, as Perl can easily distinguish between the two.
I asked what other start-of-flow control words besides for(;;) could not be used in a postfix manner. If "for(;;)" is the only one -- why? Since perl can parse it the same as any other\, why should it be the 1 control statement that it shouldn't parse -- just because you want to be able to point fingers at people\, post "LOL" comments (on PM)\, and tell people it is there bug?
How childish is that? I get kicked from the list for telling someone that those who don't change -- like the dinosaurs\, end up having problems (there was nothing personally attacking in my post\, Ricardo just didn't like being told the world was round: it was flat\, by original design\, and would be kept that way for compatibility with previous design. ;^/
It is a non-regularity in the language that doesn't need to be there. It would follow that if one thought all of the other flow-control words could be post-fixed\, then why not that one? I don't need "it's your bug" as a reason -- that's Certainly it is not rational\, technical nor compelling compelling reason why irregularities in the language shouldn't be fixed when possible (even though it is rather consistent with the reasoning[sic] why I was no longer allowed to post to the flock of believers...
That perl has so many exceptions works against it. It's a major reason why\, like python's founder\, Larry thought a complete overhaul was necessary -- because people wouldn't accept piecemeal improvements.
While the ability to "deprecate" bad design and features has improved\, grandfather logic has dominated the p5p list to the point that those pushing for change are eliminated from the list -- even when it is a something so trivial as regularizing the documentation!
The responses to the OP sufficiently address the issue raised. If the OP wants to pursue the issue\, she can submit a patch.
Closing ticket.
Thank you very much. Jim Keenan
@jkeenan - Status changed from 'open' to 'rejected'
On Sat\, Feb 2\, 2013 at 9:30 PM\, Linda Walsh via RT \< perlbug-followup@perl.org> wrote:
On Fri Feb 01 10:24:44 2013\, ikegami@adaelis.com wrote:
That passage makes no claim that Perl supports postfix C-style for loop. That passage makes no claim that Perl supports postfix C-style for loop. The bug is entirely yours.
- Eric
Nor does it claim that it does not. It says not to worry about use of "for(;;)"\, as "Perl can easily distinguish" between the two usages.
And it does. No C\<for (LIST)> was created. So even though the book is surely talking about flow control statements\, what it says is also true when you misapply it to statement modifiers.
I asked what other start-of-flow control words besides for(;;) could not
be used in a postfix manner.
Actually\, no you didn't. You filed a bug report because Perl "so clearly goes against the wording of the 'camel'." (That wouldn't be a Perl bug even if it was true!)
If you had asked that\, I would have pointed out that you're being too lazy to try it yourself or read the docs yourself.
If "for(;;)" is the only one -- why?
For starters\, it's impossible. It can't be added for consistency without still being inconsistent.
C\<while (EXPR) BLOCK> has a corresponding C\<EXPR while EXPR;>. ... C\<for (LIST) BLOCK> has a corresponding C\<EXPR for LIST;>. C\<for (EXPR;EXPR;EXPR) BLOCK> cannot have a corresponding C\<EXPR for EXPR; EXPR; EXPR;> because that would be three statements.
Secondly\, it would be next to useless . The most common usage of for(;;) is
for (my $x = 0; $x\<10; ++$x) { f($x); }
But that couldn't be written
f($x) for (my $x = 0; $x\<10; ++$x);
It would have to be written
{ my $x; f($x) for ($x = 0; $x\<10; ++$x); }
At this point\, you might as well use something else.
Migrated from rt.perl.org#116605 (status was 'rejected')
Searchable as RT116605$