New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not enough arguments for map #14195
Comments
From dean.herington@emc.comThis is a bug report for perl from dean.herington@emc.com, I don't understand the following error. I think the result of the DB<1> p map { a => 1 } 1,2,3 DB<2> $a = 'a' DB<3> p map { $a => 1 } 1,2,3 Flags: Site configuration information for perl 5.16.3: Configured by gecko at Wed Mar 13 11:25:21 2013. Summary of my perl5 (revision 5 version 16 subversion 3) configuration: Platform: Locally applied patches: @INC for perl 5.16.3: Environment for perl 5.16.3: |
From @cpansproutOn Thu Oct 30 13:55:41 2014, dean.herington@emc.com wrote:
The map entry in perlfunc says: "{" starts both hash references and blocks, so "map { ..." could be %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array) or to force an anon hash constructor use "+{": @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs to get a list of anonymous hashes each with only one entry apiece. So you could say this is not a bug, or a known limitation. However, I would like to try and fix the most obvious cases, like your examples, so that it just does the right thing. (That means doing look-ahead to see if there is a comma after the closing brace, which can only work for the most simple code.) Personally I usually do ‘map +(...), LIST’, since it always works, unless I need multiple statements in the block. -- Father Chrysostomos |
The RT System itself - Status changed from 'new' to 'open' |
From @demerphqOn 30 October 2014 22:51, Father Chrysostomos via RT <
Yet most of us would prefer to see map EXPR, LIST removed in favour of map Yves -- |
From sog@msg.mxOn 10/31/2014 01:25 AM, demerphq wrote:
I think that a note about "{;" should be included in the documentation sortiz. |
From dean.herington@emc.comThanks for making me realize that the description of `map` has been enhanced since my edition of the Perl bible was published. Personally, I would have opted for a much simpler rule: If what follows `map` is `{`, it starts a BLOCK. One can always signal an EXPR that's an anonymous hash with `+{`. I do like the `map +(...), ...` option. Thanks! -----Original Message----- On Thu Oct 30 13:55:41 2014, dean.herington@emc.com wrote:
The map entry in perlfunc says: "{" starts both hash references and blocks, so "map { ..." could be %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array) or to force an anon hash constructor use "+{": @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs to get a list of anonymous hashes each with only one entry apiece. So you could say this is not a bug, or a known limitation. However, I would like to try and fix the most obvious cases, like your examples, so that it just does the right thing. (That means doing look-ahead to see if there is a comma after the closing brace, which can only work for the most simple code.) Personally I usually do ‘map +(...), LIST’, since it always works, unless I need multiple statements in the block. -- Father Chrysostomos |
From @janduboisOn Fri, Oct 31, 2014 at 12:25 AM, demerphq <demerphq@gmail.com> wrote:
Seriously? I bet that would break tons of existing code. E.g. I for (map lc, grep defined, @list) { ... } And I consider this concise syntax very "perlish". :) I also find it for (map { lc } grep { defined } @list) { Anyways, I think removal of "map EXPR, LIST" would have to be enabled Cheers, |
From @demerphqOn 31 October 2014 17:42, Jan Dubois <jand@activestate.com> wrote:
frequently use expressions like I didnt say i think its feasible. I just think its what most of us would
I dont much like either personally. Three loops for one list? But whatever.
I dont think we can remove it at all. I just wish we could. Yves -- |
From @ikegamiOn Thu, Oct 30, 2014 at 5:51 PM, Father Chrysostomos via RT <
And to force the block syntax, you can use: map {; ... } LIST |
From @cpansproutOn Fri Oct 31 00:46:13 2014, sortiz wrote:
The docs did already mention { +... }, which works, too; but I added {; to the documentation nonetheless in commit 24fe90a. I don’t consider this issue resolved until the parser can search past the closing brace, at least for the simple cases of {string, string} and {var, var}, and combinations of those. -- Father Chrysostomos |
Migrated from rt.perl.org#123090 (status was 'open')
Searchable as RT123090$
The text was updated successfully, but these errors were encountered: