Closed p5pRT closed 9 years ago
The => operator is a special comma which quotes its LHS. As a convenience Perl allows a trailing comma in a list:
(1\, 2\,)
That is useful\, but it may make less sense to allow
(1\, 2 =>)
Since => is normally used to indicate the programmer's intention of a key=>value pair\, as well as for its quoting behaviour\, allowing a trailing => loses the opportunity to check for certain mistakes.
Similarly I suggest that it would be a useful check to forbid having a list item sandwiched between two => operators in the program text\, as
(1 => 2 => 3)
Finally\, while there may be reasons for skipping over repeated commas in a list (though I do not know what the reasons are)\, this should not apply to the fat comma:
(1 => => 2)
All of these checks would help to catch some mistakes such as cut- and-paste errors at compile time rather than run time. I accept that some of the odd constructs above may be intentionally used in existing code. In particular (a => b => c) may be used as an attempt by the programmer to show the flow of data\, or 'wish-fulfilment operator' as Conway calls it. But I think the other two checks should be feasible.
On Fri Jan 23 23:54:22 2015\, eda@waniasset.com wrote:
This is a bug report for perl from eda@waniasset.com\, generated with the help of perlbug 1.39 running under perl 5.18.4.
----------------------------------------------------------------- [Please describe your issue here]
The => operator is a special comma which quotes its LHS. As a convenience Perl allows a trailing comma in a list:
(1\, 2\,)
That is useful\, but it may make less sense to allow
(1\, 2 =>)
Since => is normally used to indicate the programmer's intention of a key=>value pair\, as well as for its quoting behaviour\, allowing a trailing => loses the opportunity to check for certain mistakes.
You have too narrow an interpretation of programmers' intentions for their use of the '=>' operator -- and you have not cited any "mistakes" for which one should check.
It took me only a few minutes using http://grep.cpan.me (dg++) to find a legitimate example of '=> )'. There are three unit tests in CPAN distro File-Find-Rule (starting at https://metacpan.org/source/RCLAMP/File-Find-Rule-0.33/t/File-Find-Rule.t#L222) which use 'discard =>)' as part of testing that distribution's procedural interface (File::Find::Rule::Procedural).
Similarly I suggest that it would be a useful check to forbid having a list item sandwiched between two => operators in the program text\, as
(1 => 2 => 3)
https://metacpan.org/source/RCLAMP/File-Find-Rule-0.33/t/File-Find-Rule.t#L167 provides a perfectly legitimate use of this syntax.
Finally\, while there may be reasons for skipping over repeated commas in a list (though I do not know what the reasons are)\, this should not apply to the fat comma:
(1 => => 2)
Why\, other than it looks a bit inelegant?
More to the point\, why should we impose this restriction *in the Perl 5 core*? If\, for instance\, you wanted to rule out this syntax as part of your "shop style"\, you could do so with a Perl-Critic rule. https://metacpan.org/source/KRYDE/Perl-Critic-Pulp-89/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitEmptyCommas.pm#L1 appears to do this.
All of these checks would help to catch some mistakes such as cut- and-paste errors at compile time rather than run time. I accept that some of the odd constructs above may be intentionally used in existing code. In particular (a => b => c) may be used as an attempt by the programmer to show the flow of data\, or 'wish-fulfilment operator' as Conway calls it. But I think the other two checks should be feasible.
I don't see any benefits from implementing this feature request that outweigh (a) the effort it would take to implement this in core; (b) the grief that new and frivolous warnings would cause in existing CPAN (and\, I suspect\, production) code.
Thank you very much.
-- James E Keenan (jkeenan@cpan.org)
The RT System itself - Status changed from 'new' to 'open'
* Ed Avis \perlbug\-followup@​perl\.org [2015-01-24 08:55]:
(1\, 2 =>)
-1\, done that on purpose on a handful of occasions.
(1 => 2 => 3)
-1\, done that on purpose a lot. (-37 really\, if that made a difference.)
(1 => => 2)
-0. I wouldnât like finding this in code\, and I guess if it did warn at compile time (without an error) I wouldnât mind that it did. But I donât see the pay-off for adding a warning.
This is a job for a linter.
Thanks for your reply. I guess => really is used just as a quoting mechanism sometimes\, and not just as a way of creating k=>v pairs.
While => => is useless\, it is also harmless (like \,\,). While I don't think anyone would advocate adding it to the language if it didn't already exist\, it may not be worth the effort to remove it either. The only real argument in favour might be that it'd make it possible to assign some useful semantics to => => later\, or perhaps to remove an ambiguity in the grammar at some future date.
-- Ed Avis \eda@​waniasset\.com
On Sat\, Jan 24\, 2015 at 08:26:03PM +0000\, Ed Avis wrote:
Thanks for your reply. I guess => really is used just as a quoting mechanism sometimes\, and not just as a way of creating k=>v pairs.
While => => is useless\, it is also harmless (like \,\,). While I don't think anyone would advocate adding it to the language if it didn't already exist\, it may not be worth the effort to remove it either. The only real argument in favour might be that it'd make it possible to assign some useful semantics to => => later\, or perhaps to remove an ambiguity in the grammar at some future date.
"=> =>" may be useless\, "\, =>" (or "\,=>") is not.
I use it often when I want the visual impact of =>\, without the auto-quoting:
use constant APPLE => 1; use constant BANANA => 2;
my %fruit_colours = ( APPLE \,=> "red"\, BANANA \,=> "yellow"\, );
Abigail
On Sat Jan 24 15:19:48 2015\, abigail@abigail.be wrote:
On Sat\, Jan 24\, 2015 at 08:26:03PM +0000\, Ed Avis wrote:
Thanks for your reply. I guess => really is used just as a quoting mechanism sometimes\, and not just as a way of creating k=>v pairs.
While => => is useless\, it is also harmless (like \,\,). While I don't think anyone would advocate adding it to the language if it didn't already exist\, it may not be worth the effort to remove it either. The only real argument in favour might be that it'd make it possible to assign some useful semantics to => => later\, or perhaps to remove an ambiguity in the grammar at some future date.
"=> =>" may be useless\, "\, =>" (or "\,=>") is not.
I use it often when I want the visual impact of =>\, without the auto-quoting:
use constant APPLE => 1; use constant BANANA => 2;
my %fruit_colours = ( APPLE \,=> "red"\, BANANA \,=> "yellow"\, );
I sometimes use =>=> to set things off with more emphasis.
--
Father Chrysostomos
Thanks all for your replies. I think this can be closed - unless the p5-porters think it worthwhile to explicitly document that \,\, is equivalent to \, and =>=> equivalent to =>?
On Sun\, Jan 25\, 2015 at 8:11 PM\, Ed Avis via RT \perlbug\-followup@​perl\.org wrote:
Thanks all for your replies. I think this can be closed - unless the p5-porters think it worthwhile to explicitly document that \,\, is equivalent to \, and =>=> equivalent to =>?
From perlop: "The => operator is a synonym for the comma except that it causes its left operand to be interpreted as a string[...]".
So that establishes that it's like "\,"\, do we document anywhere that repeated "\," (or ";" for that matter) fold down to one?
On Sun Jan 25 13:14:43 2015\, avarab@gmail.com wrote:
On Sun\, Jan 25\, 2015 at 8:11 PM\, Ed Avis via RT \perlbug\-followup@​perl\.org wrote:
Thanks all for your replies. I think this can be closed - unless the p5-porters think it worthwhile to explicitly document that \,\, is equivalent to \, and =>=> equivalent to =>?
From perlop: "The => operator is a synonym for the comma except that it causes its left operand to be interpreted as a string[...]".
So that establishes that it's like "\,"\, do we document anywhere that repeated "\," (or ";" for that matter) fold down to one?
That might be useful -- but let's get a patch in a new RT for discussion so that we can close this ticket.
Thank you very much.
-- James E Keenan (jkeenan@cpan.org)
On Sun Jan 25 13:17:13 2015\, jkeenan wrote:
On Sun Jan 25 13:14:43 2015\, avarab@gmail.com wrote:
On Sun\, Jan 25\, 2015 at 8:11 PM\, Ed Avis via RT \perlbug\-followup@​perl\.org wrote:
Thanks all for your replies. I think this can be closed - unless the p5-porters think it worthwhile to explicitly document that \,\, is equivalent to \, and =>=> equivalent to =>?
From perlop: "The => operator is a synonym for the comma except that it causes its left operand to be interpreted as a string[...]".
So that establishes that it's like "\,"\, do we document anywhere that repeated "\," (or ";" for that matter) fold down to one?
That might be useful -- but let's get a patch in a new RT for discussion so that we can close this ticket.
perldata already has a paragraph on this. Search for 1\,\,\,3.
--
Father Chrysostomos
On Sun Jan 25 17:16:34 2015\, sprout wrote:
On Sun Jan 25 13:17:13 2015\, jkeenan wrote:
On Sun Jan 25 13:14:43 2015\, avarab@gmail.com wrote:
On Sun\, Jan 25\, 2015 at 8:11 PM\, Ed Avis via RT \perlbug\-followup@​perl\.org wrote:
Thanks all for your replies. I think this can be closed - unless the p5-porters think it worthwhile to explicitly document that \,\, is equivalent to \, and =>=> equivalent to =>?
From perlop: "The => operator is a synonym for the comma except that it causes its left operand to be interpreted as a string[...]".
So that establishes that it's like "\,"\, do we document anywhere that repeated "\," (or ";" for that matter) fold down to one?
That might be useful -- but let's get a patch in a new RT for discussion so that we can close this ticket.
perldata already has a paragraph on this. Search for 1\,\,\,3.
On that basis\, I think we can close this ticket.
Thank you very much.
-- James E Keenan (jkeenan@cpan.org)
@jkeenan - Status changed from 'open' to 'rejected'
Migrated from rt.perl.org#123664 (status was 'rejected')
Searchable as RT123664$