Skip to content
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

map failing to parse with 2 element unparenthesis list in a block #14258

Open
p5pRT opened this issue Nov 19, 2014 · 11 comments
Open

map failing to parse with 2 element unparenthesis list in a block #14258

p5pRT opened this issue Nov 19, 2014 · 11 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 19, 2014

Migrated from rt.perl.org#123259 (status was 'open')

Searchable as RT123259$

@p5pRT
Copy link
Author

p5pRT commented Nov 19, 2014

From miller.hall@gmail.com

This is a bug report for perl from miller.hall@​gmail.com,
generated with the help of perlbug 1.40 running under perl 5.20.1.


The following will not compile

  use warnings;
  use strict;

  my $vex = [ { _dirty => "muddy waters" } ];

  print map { "$_", $vex->[$_]{_dirty} } ( 0 .. $#$vex );

It will throw the error

  syntax error at map.pl line 8, near "} ( "

To fix, simply put parenthesis around the list in the block. Alternatively,
can be hidden by removing the quotes around the any variable, but that was
needed in the original usage.



Flags​:
  category=core
  severity=low


Site configuration information for perl 5.20.1​:

Configured by miller at Tue Sep 23 16​:58​:21 PDT 2014.

Summary of my perl5 (revision 5 version 20 subversion 1) configuration​:
 
  Platform​:
  osname=darwin, osvers=13.4.0, archname=darwin-2level
  uname='darwin millers-macbook-air.local 13.4.0 darwin kernel version 13.4.0​: sun aug 17 19​:50​:11 pdt 2014; root​:xnu-2422.115.4~1release_x86_64 x86_64 '
  config_args='-de -Dprefix=/Users/miller/perl5/perlbrew/perls/perl-5.20.0 -Aeval​:scriptdir=/Users/miller/perl5/perlbrew/perls/perl-5.20.0/bin'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=undef, usemultiplicity=undef
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
  optimize='-O3',
  cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /usr/lib
  libs=-ldbm -ldl -lm -lutil -lc
  perllibs=-ldl -lm -lutil -lc
  libc=, so=dylib, useshrplib=false, libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector'


@​INC for perl 5.20.1​:
  /Users/miller/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.1/darwin-2level
  /Users/miller/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.1
  /Users/miller/perl5/perlbrew/perls/perl-5.20.0/lib/5.20.1/darwin-2level
  /Users/miller/perl5/perlbrew/perls/perl-5.20.0/lib/5.20.1
  /Users/miller/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/darwin-2level
  /Users/miller/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0
  /Users/miller/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl
  .


Environment for perl 5.20.1​:
  DYLD_LIBRARY_PATH (unset)
  HOME=/Users/miller
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/local/bin​:/Users/miller/perl5/perlbrew/bin​:/Users/miller/perl5/perlbrew/perls/perl-5.20.0/bin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/sbin​:/sbin
  PERLBREW_BASHRC_VERSION=0.69
  PERLBREW_HOME=/Users/miller/.perlbrew
  PERLBREW_MANPATH=/Users/miller/perl5/perlbrew/perls/perl-5.20.0/man
  PERLBREW_PATH=/Users/miller/perl5/perlbrew/bin​:/Users/miller/perl5/perlbrew/perls/perl-5.20.0/bin
  PERLBREW_PERL=perl-5.20.0
  PERLBREW_ROOT=/Users/miller/perl5/perlbrew
  PERLBREW_VERSION=0.69
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2014

From @jkeenan

On Wed Nov 19 09​:58​:41 2014, miller.hall@​gmail.com wrote​:

This is a bug report for perl from miller.hall@​gmail.com,
generated with the help of perlbug 1.40 running under perl 5.20.1.

-----------------------------------------------------------------
The following will not compile

use warnings;
use strict;

my $vex = [ { _dirty => "muddy waters" } ];

print map { "$_", $vex->[$_]{_dirty} } ( 0 .. $#$vex );

It will throw the error

syntax error at map.pl line 8, near "} ( "

To fix, simply put parenthesis around the list in the block.
Alternatively,
can be hidden by removing the quotes around the any variable, but that
was
needed in the original usage.

This can be seen more clearly if we clear out some non-essentials​:

#####
$ perl -E 'print map { "$_", 'alpha' } (0);'
syntax error at -e line 1, near "} ("
Execution of -e aborted due to compilation errors.

$ perl -E 'say map { $_, 'alpha' } (0);'
0alpha

$ perl -E 'say map { ("$_", 'alpha') } (0);'
0alpha
#####

I suspect that this is documented behavior (hence, not a bug), though I don't have the citation yet.

Thank you very much.
Jim Keenan


---
Flags​:
category=core
severity=low
---
Site configuration information for perl 5.20.1​:

Configured by miller at Tue Sep 23 16​:58​:21 PDT 2014.

Summary of my perl5 (revision 5 version 20 subversion 1)
configuration​:

Platform​:
osname=darwin, osvers=13.4.0, archname=darwin-2level
uname='darwin millers-macbook-air.local 13.4.0 darwin kernel version
13.4.0​: sun aug 17 19​:50​:11 pdt 2014; root​:xnu-
2422.115.4~1release_x86_64 x86_64 '
config_args='-de -Dprefix=/Users/miller/perl5/perlbrew/perls/perl-
5.20.0 -Aeval​:scriptdir=/Users/miller/perl5/perlbrew/perls/perl-
5.20.0/bin'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing
-pipe -fstack-protector -I/usr/local/include',
optimize='-O3',
cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.2.1 Compatible Apple LLVM 6.0 (clang-
600.0.51)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-
protector -L/usr/local/lib'
libpth=/usr/local/lib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib
/usr/lib
libs=-ldbm -ldl -lm -lutil -lc
perllibs=-ldl -lm -lutil -lc
libc=, so=dylib, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup
-L/usr/local/lib -fstack-protector'

---
@​INC for perl 5.20.1​:
/Users/miller/perl5/perlbrew/perls/perl-
5.20.0/lib/site_perl/5.20.1/darwin-2level
/Users/miller/perl5/perlbrew/perls/perl-
5.20.0/lib/site_perl/5.20.1
/Users/miller/perl5/perlbrew/perls/perl-5.20.0/lib/5.20.1/darwin-
2level
/Users/miller/perl5/perlbrew/perls/perl-5.20.0/lib/5.20.1
/Users/miller/perl5/perlbrew/perls/perl-
5.20.0/lib/site_perl/5.20.0/darwin-2level
/Users/miller/perl5/perlbrew/perls/perl-
5.20.0/lib/site_perl/5.20.0
/Users/miller/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl
.

---
Environment for perl 5.20.1​:
DYLD_LIBRARY_PATH (unset)
HOME=/Users/miller
LANG=en_US.UTF-8
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/usr/local/bin​:/Users/miller/perl5/perlbrew/bin​:/Users/miller/perl5/perlbrew/perls/perl-
5.20.0/bin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/sbin​:/sbin
PERLBREW_BASHRC_VERSION=0.69
PERLBREW_HOME=/Users/miller/.perlbrew
PERLBREW_MANPATH=/Users/miller/perl5/perlbrew/perls/perl-
5.20.0/man
PERLBREW_PATH=/Users/miller/perl5/perlbrew/bin​:/Users/miller/perl5/perlbrew/perls/perl-
5.20.0/bin
PERLBREW_PERL=perl-5.20.0
PERLBREW_ROOT=/Users/miller/perl5/perlbrew
PERLBREW_VERSION=0.69
PERL_BADLANG (unset)
SHELL=/bin/bash

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2014

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2014

From @cpansprout

On Wed Nov 19 16​:04​:21 2014, jkeenan wrote​:

On Wed Nov 19 09​:58​:41 2014, miller.hall@​gmail.com wrote​:

This is a bug report for perl from miller.hall@​gmail.com,
generated with the help of perlbug 1.40 running under perl 5.20.1.

-----------------------------------------------------------------
The following will not compile

use warnings;
use strict;

my $vex = [ { _dirty => "muddy waters" } ];

print map { "$_", $vex->[$_]{_dirty} } ( 0 .. $#$vex );

It will throw the error

syntax error at map.pl line 8, near "} ( "

To fix, simply put parenthesis around the list in the block.
Alternatively,
can be hidden by removing the quotes around the any variable, but
that
was
needed in the original usage.

This can be seen more clearly if we clear out some non-essentials​:

#####
$ perl -E 'print map { "$_", 'alpha' } (0);'
syntax error at -e line 1, near "} ("
Execution of -e aborted due to compilation errors.

$ perl -E 'say map { $_, 'alpha' } (0);'
0alpha

$ perl -E 'say map { ("$_", 'alpha') } (0);'
0alpha
#####

I suspect that this is documented behavior (hence, not a bug), though
I don't have the citation yet.

perlfunc/map

This same bug gets reported again, and again, and again. So, while it is documented, I’m going to consider it a documented bug. It is fixable for simple cases.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2014

From @jkeenan

On Wed Nov 19 16​:14​:04 2014, sprout wrote​:

On Wed Nov 19 16​:04​:21 2014, jkeenan wrote​:

On Wed Nov 19 09​:58​:41 2014, miller.hall@​gmail.com wrote​:

This is a bug report for perl from miller.hall@​gmail.com,
generated with the help of perlbug 1.40 running under perl 5.20.1.

-----------------------------------------------------------------
The following will not compile

use warnings;
use strict;

my $vex = [ { _dirty => "muddy waters" } ];

print map { "$_", $vex->[$_]{_dirty} } ( 0 .. $#$vex );

It will throw the error

syntax error at map.pl line 8, near "} ( "

To fix, simply put parenthesis around the list in the block.
Alternatively,
can be hidden by removing the quotes around the any variable, but
that
was
needed in the original usage.

This can be seen more clearly if we clear out some non-essentials​:

#####
$ perl -E 'print map { "$_", 'alpha' } (0);'
syntax error at -e line 1, near "} ("
Execution of -e aborted due to compilation errors.

$ perl -E 'say map { $_, 'alpha' } (0);'
0alpha

$ perl -E 'say map { ("$_", 'alpha') } (0);'
0alpha
#####

I suspect that this is documented behavior (hence, not a bug), though
I don't have the citation yet.

perlfunc/map

Specifically​:

#####
"{" starts both hash references and blocks, so "map { ..." could beeither the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look ahead for the closing "}" it has to take a guess at which it's dealing with based on what it finds just after the "{". Usually it gets it right, but if it doesn't it won't realize something is wrong until it gets to the "}" and encounters the missing (or unexpected) comma. The syntax error will be reported close to the "}", but you'll need to change something near the "{" such as using a unary "+" or semicolon to give Perl some help​:

  %hash = map { "\L$_" => 1 } @​array # perl guesses EXPR. wrong
  %hash = map { +"\L$_" => 1 } @​array # perl guesses BLOCK. right
#####

This same bug gets reported again, and again, and again. So, while it
is documented, I’m going to consider it a documented bug. It is
fixable for simple cases.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2014

From @demerphq

On 20 November 2014 01​:23, James E Keenan via RT <perlbug-followup@​perl.org>
wrote​:

On Wed Nov 19 16​:14​:04 2014, sprout wrote​:

On Wed Nov 19 16​:04​:21 2014, jkeenan wrote​:

On Wed Nov 19 09​:58​:41 2014, miller.hall@​gmail.com wrote​:

This is a bug report for perl from miller.hall@​gmail.com,
generated with the help of perlbug 1.40 running under perl 5.20.1.

-----------------------------------------------------------------
The following will not compile

use warnings;
use strict;

my $vex = [ { _dirty => "muddy waters" } ];

print map { "$_", $vex->[$_]{_dirty} } ( 0 .. $#$vex );

It will throw the error

syntax error at map.pl line 8, near "} ( "

To fix, simply put parenthesis around the list in the block.
Alternatively,
can be hidden by removing the quotes around the any variable, but
that
was
needed in the original usage.

This can be seen more clearly if we clear out some non-essentials​:

#####
$ perl -E 'print map { "$_", 'alpha' } (0);'
syntax error at -e line 1, near "} ("
Execution of -e aborted due to compilation errors.

$ perl -E 'say map { $_, 'alpha' } (0);'
0alpha

$ perl -E 'say map { ("$_", 'alpha') } (0);'
0alpha
#####

I suspect that this is documented behavior (hence, not a bug), though
I don't have the citation yet.

perlfunc/map

Specifically​:

#####
"{" starts both hash references and blocks, so "map { ..." could beeither
the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look
ahead for the closing "}" it has to take a guess at which it's dealing with
based on what it finds just after the "{". Usually it gets it right, but if
it doesn't it won't realize something is wrong until it gets to the "}" and
encounters the missing (or unexpected) comma. The syntax error will be
reported close to the "}", but you'll need to change something near the "{"
such as using a unary "+" or semicolon to give Perl some help​:

%hash = map { "\L$_" => 1 } @​array # perl guesses EXPR. wrong
%hash = map { +"\L$_" => 1 } @​array # perl guesses BLOCK. right
#####

This same bug gets reported again, and again, and again. So, while it
is documented, I’m going to consider it a documented bug. It is
fixable for simple cases.

It is fixable for all cases. Simply always write​:

map {; .... } @​list;

That leading semicolon is critical. IMO the advice to use a plus is broken.

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2014

From miller.hall@gmail.com

It was pointed out that is documented in perldoc for map.

Would therefore delete this bug report, but don't know now :)

Regards,
- Miller

On Wed, Nov 19, 2014 at 9​:58 AM, <perlbug-followup@​perl.org> wrote​:

Greetings,

This message has been automatically generated in response to the
creation of a perl bug report regarding​:
"map failing to parse with 2 element unparenthesis list in a block".

There is no need to reply to this message right now. Your ticket has been
assigned an ID of [perl #123259].

You can view your ticket at
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=123259

Within the next 24 to 72 hours, your message will be posted to the Perl 5
Porters mailing list. Please be patient!

Please include the string​:

[perl #123259]

in the subject line of all future correspondence about this issue. To do
so,
you may reply to this message (please delete unnecessary quotes and text.)

Thank you,
perlbug-followup@​perl.org

-------------------------------------------------------------------------
Message-ID​: <5.20.1_62633_1416419488@​Millers-MacBook-Air.local>
X-Spam-Status​: No, hits=-4.3 required=8.0
tests=BAYES_00,DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,PERLBUG_CONF,SPF_SOFTFAIL,URIBL_BLOCKED
Return-Path​: <miller.hall@​gmail.com>
Reply-To​: miller.hall@​gmail.com
Delivered-To​: rt-perl5@​rt.perl.org
Delivered-To​: perlbug@​perl.org
To​: perlbug@​perl.org
From​: miller.hall@​gmail.com
X-Spam-Check-BY​: la.mx.develooper.com
Date​: Wed, 19 Nov 2014 09​:58​:29 -0800 (PST)
Received​: (qmail 21453 invoked by uid 225); 19 Nov 2014 17​:58​:37 -0000
Received​: (qmail 21449 invoked by alias); 19 Nov 2014 17​:58​:36 -0000
Received​: from 50-204-19-9-static.hfc.comcastbusiness.net (HELO
Millers-MacBook-Air.local) (50.204.19.9) by la.mx.develooper.com
(qpsmtpd/0.28) with SMTP; Wed, 19 Nov 2014 09​:58​:34 -0800
Received​: by Millers-MacBook-Air.local (Postfix, from userid 501) id
6C899631EA8; Wed, 19 Nov 2014 09​:58​:29 -0800 (PST)
Subject​: map failing to parse with 2 element unparenthesis list in a block
From miller.hall@​gmail.com Wed Nov 19 17​:58​:37 2014
X-RT-Original-Encoding​: ascii
content-type​: text/plain; charset="utf-8"
X-RT-Interface​: Email

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2014

From @cpansprout

On Thu Nov 20 05​:24​:40 2014, demerphq wrote​:

map {; .... } @​list;

That leading semicolon is critical. IMO the advice to use a plus is
broken.

How is it broken?

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2014

From @demerphq

On 20 November 2014 14​:58, Father Chrysostomos via RT <
perlbug-followup@​perl.org> wrote​:

On Thu Nov 20 05​:24​:40 2014, demerphq wrote​:

map {; .... } @​list;

That leading semicolon is critical. IMO the advice to use a plus is
broken.

How is it broken?

The advice is broken because the heuristic involving plus breaks the
opposite case​:

$ perl -wle'my @​things= map { +3, 1 }, 1..10; print @​things'
syntax error at -e line 1, near "},"
Execution of -e aborted due to compilation errors.

Also it is of poor value because it is not very general​:

$ perl -wle'my @​things= map { no warnings; $_+1 } 1..10; print @​things'
"no" not allowed in expression at -e line 1, at end of line
BEGIN not safe after errors--compilation aborted at -e line 1.
$ perl -wle'my @​things= map { +no warnings; $_+1 } 1..10; print @​things'
"no" not allowed in expression at -e line 1, at end of line
syntax error at -e line 1, near "+no warnings"
Execution of -e aborted due to compilation errors.
$ perl -wle'my @​things= map {; no warnings; $_+1 } 1..10; print @​things'
234567891011

Advising people to use semicolon works reliably, and does not involve a
heuristic which breaks legitimate code in the opposite case. A semicolon is
always illegal in an anonymous hash construct. Not so plus.

Yves

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2014

From @ikegami

On Thu, Nov 20, 2014 at 8​:24 AM, demerphq <demerphq@​gmail.com> wrote​:

It is fixable for all cases. Simply always write​:

map {; .... } @​list;

That's perverse!

In the very rare case where you want to create a list of hash refs,
disambiguate

map { +{ value => $_ } } LIST
map +{ value => $_ }, LIST

The rest of the time "map {" should always be "map BLOCK".

The endless stream of questions and bug reports about this justifies the
change.

- Eric

@p5pRT
Copy link
Author

p5pRT commented Nov 20, 2014

From @demerphq

On 20 November 2014 16​:09, Eric Brine <ikegami@​adaelis.com> wrote​:

On Thu, Nov 20, 2014 at 8​:24 AM, demerphq <demerphq@​gmail.com> wrote​:

It is fixable for all cases. Simply always write​:

map {; .... } @​list;

That's perverse!

I don't agree. It is perfectly normal. And the only reliable way to force
map BLOCK semantics. Plus is not reliable. (You cannot use it for things
like "no warnings").

In the very rare case where you want to create a list of hash refs,
disambiguate

map { +{ value => $_ } } LIST
map +{ value => $_ }, LIST

The rest of the time "map {" should always be "map BLOCK".

If that ever becomes true then fine. But its not true now, and the advice
to use + IMO is bad.

The endless stream of questions and bug reports about this justifies the
change.

Personally I would like to see map EXPR, LIST go away entirely.

Yves

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants