Re: [perl #37039] perlref documentation about optional - is too vague
Yitzchak Scott-Thoennes wrote: I think I like the idea, and the patch seems safe. What I don't like, though, is the lack of tests for this patch. Also, a minor concern is that people might unknowingly write non-backwards-compatible code with 5.10 by using this construct. Some basic tests: Thanks, both patches applied as change #25399. As to your minor concern, that may be a reason to not include it in maint. (Whether it's a bugfix or enhancement depends on how you interpret the doc.) I don't know how Nicholas is going to interpret it, but personnally I wouldn't include it. -- The man does not exist who, outside his own specialty, is not credulous. -- Borges
Re: [perl #37039] perlref documentation about optional - is too vague
On Mon, Sep 05, 2005 at 08:10:20AM -0700, Yitzchak Scott-Thoennes wrote: On Mon, Sep 05, 2005 at 04:41:56PM +0200, Rafael Garcia-Suarez wrote: On 9/5/05, Yitzchak Scott-Thoennes [EMAIL PROTECTED] wrote: Any other feedback on making (LIST)[LIST]- not need the -? I think I like the idea, and the patch seems safe. What I don't like, though, is the lack of tests for this patch. Also, a minor concern is that people might unknowingly write non-backwards-compatible code with 5.10 by using this construct. Some basic tests: --- t/op/ref.t.orig 2005-01-06 10:11:05.0 -0800 +++ t/op/ref.t 2005-09-05 08:05:18.629808000 -0700 @@ -8,7 +8,7 @@ require 'test.pl'; use strict qw(refs subs); -plan (89); +plan (96); # Test glob operations. @@ -425,6 +425,23 @@ 'Accessing via a different NUL-containing name gives nothing'); } +# test derefs after list slice + +is ( ({foo = bar})[0]{foo}, bar, 'hash deref from list slice w/o -' ); +is ( ({foo = bar})[0]-{foo}, bar, 'hash deref from list slice w/ -' ); +is ( ([qw/foo bar/])[0][1], bar, 'array deref from list slice w/o -' ); +is ( ([qw/foo bar/])[0]-[1], bar, 'array deref from list slice w/ -' ); +is ( (sub {bar})[0](), bar, 'code deref from list slice w/o -' ); +is ( (sub {bar})[0]-(), bar, 'code deref from list slice w/ -' ); + +# deref on empty list shouldn't autovivify +{ +local $@; +eval { ()[0]{foo} }; +like ( $@, Can't use an undefined value as a HASH reference, + deref of undef from list slice fails ); +} + # Bit of a hack to make test.pl happy. There are 3 more tests after it leaves. $test = curr_test(); curr_test($test + 3); As to your minor concern, that may be a reason to not include it in maint. (Whether it's a bugfix or enhancement depends on how you interpret the doc.) Ping?
Re: [perl #37039] perlref documentation about optional - is too vague
On Thu, Sep 01, 2005 at 05:41:36PM -0700, Yitzchak Scott-Thoennes wrote: On Wed, Aug 31, 2005 at 06:07:11AM -0700, japhy @ perlmonk. org wrote: In 'perlref', item #3 of 'Using References' says One more thing here. The arrow is optional between brackets sub- scripts, so you can shrink the above down to $array[$x]{foo}[0] = January; This led me to believe I could write: sub foo { ...; return @data } my $x = (foo())[0][1]; which would have the same effect as my @return = foo(); my $x = $return[0][1]; However, it's a syntax error. This can be fixed with an arrow: my $x = (foo())[0]-[1]; The problem is that (foo())[0] is NOT analogous to $array[$x]; one is a list slice, the other is a single element from an array. But the documentation does not distinguish when it says optional between brackets subscripts [sic]. I think the language there should be polished a bit. I don't see any reason not to just make it legal syntax instead: --- p/perly.y.orig 2005-06-08 01:32:12.0 -0700 +++ p/perly.y 2005-08-31 11:02:57.520643200 -0700 @@ -487,6 +487,10 @@ subscripted:star '{' expr ';' '}' | subscripted '(' ')'/* $foo-{bar}-() */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, newCVREF(0, scalar($1))); } + | '(' expr ')' '[' expr ']'/* list slice */ + { $$ = newSLICEOP(0, $5, $2); } + | '(' ')' '[' expr ']' /* empty list slice! */ + { $$ = newSLICEOP(0, $4, Nullop); } ; /* Binary operators between terms */ @@ -622,10 +626,6 @@ term : termbinop { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));} | subscripted { $$ = $1; } - | '(' expr ')' '[' expr ']'/* list slice */ - { $$ = newSLICEOP(0, $5, $2); } - | '(' ')' '[' expr ']' /* empty list slice! */ - { $$ = newSLICEOP(0, $4, Nullop); } | ary '[' expr ']' /* array slice */ { $$ = prepend_elem(OP_ASLICE, newOP(OP_PUSHMARK, 0), End of Patch. Any other feedback on making (LIST)[LIST]- not need the -?
Re: [perl #37039] perlref documentation about optional - is too vague
On 9/5/05, Yitzchak Scott-Thoennes [EMAIL PROTECTED] wrote: Any other feedback on making (LIST)[LIST]- not need the -? I think I like the idea, and the patch seems safe. What I don't like, though, is the lack of tests for this patch. Also, a minor concern is that people might unknowingly write non-backwards-compatible code with 5.10 by using this construct.
Re: [perl #37039] perlref documentation about optional - is too vague
On Mon, Sep 05, 2005 at 04:41:56PM +0200, Rafael Garcia-Suarez wrote: On 9/5/05, Yitzchak Scott-Thoennes [EMAIL PROTECTED] wrote: Any other feedback on making (LIST)[LIST]- not need the -? I think I like the idea, and the patch seems safe. What I don't like, though, is the lack of tests for this patch. Also, a minor concern is that people might unknowingly write non-backwards-compatible code with 5.10 by using this construct. Some basic tests: --- t/op/ref.t.orig 2005-01-06 10:11:05.0 -0800 +++ t/op/ref.t 2005-09-05 08:05:18.629808000 -0700 @@ -8,7 +8,7 @@ require 'test.pl'; use strict qw(refs subs); -plan (89); +plan (96); # Test glob operations. @@ -425,6 +425,23 @@ 'Accessing via a different NUL-containing name gives nothing'); } +# test derefs after list slice + +is ( ({foo = bar})[0]{foo}, bar, 'hash deref from list slice w/o -' ); +is ( ({foo = bar})[0]-{foo}, bar, 'hash deref from list slice w/ -' ); +is ( ([qw/foo bar/])[0][1], bar, 'array deref from list slice w/o -' ); +is ( ([qw/foo bar/])[0]-[1], bar, 'array deref from list slice w/ -' ); +is ( (sub {bar})[0](), bar, 'code deref from list slice w/o -' ); +is ( (sub {bar})[0]-(), bar, 'code deref from list slice w/ -' ); + +# deref on empty list shouldn't autovivify +{ +local $@; +eval { ()[0]{foo} }; +like ( $@, Can't use an undefined value as a HASH reference, + deref of undef from list slice fails ); +} + # Bit of a hack to make test.pl happy. There are 3 more tests after it leaves. $test = curr_test(); curr_test($test + 3); As to your minor concern, that may be a reason to not include it in maint. (Whether it's a bugfix or enhancement depends on how you interpret the doc.)
Re: [perl #37039] perlref documentation about optional - is too vague
On Thu, Sep 01, 2005 at 05:41:36PM -0700, Yitzchak Scott-Thoennes wrote: BTW, cygwin only has bison 1.875b, not the allowed 1.875 or 1.875c, but it seemed to work. I also note that Debian stable has 1.875d; would it make sense to just allow any 1.875* version? --- p/regen_perly.pl.orig 2005-05-07 04:36:14.0 -0700 +++ p/regen_perly.pl2005-08-31 11:16:02.86992 -0700 @@ -65,7 +65,7 @@ # the test below to allow that version too. DAPM Feb 04. my $version = `$bison -V`; -unless ($version =~ /\b(1\.875c?|2\.0)\b/) { die EOF; } +unless ($version =~ /\b(1\.875[a-z]?|2\.0)\b/) { die EOF; } You have the wrong version of bison in your path; currently 1.875 or 2.0 is required. Try installing End of Patch. Dave, any comment on this?
Re: [perl #37039] perlref documentation about optional - is too vague
On Sun, Sep 04, 2005 at 02:38:14AM -0700, Yitzchak Scott-Thoennes wrote: On Thu, Sep 01, 2005 at 05:41:36PM -0700, Yitzchak Scott-Thoennes wrote: BTW, cygwin only has bison 1.875b, not the allowed 1.875 or 1.875c, but it seemed to work. I also note that Debian stable has 1.875d; would it make sense to just allow any 1.875* version? --- p/regen_perly.pl.orig 2005-05-07 04:36:14.0 -0700 +++ p/regen_perly.pl2005-08-31 11:16:02.86992 -0700 @@ -65,7 +65,7 @@ # the test below to allow that version too. DAPM Feb 04. my $version = `$bison -V`; -unless ($version =~ /\b(1\.875c?|2\.0)\b/) { die EOF; } +unless ($version =~ /\b(1\.875[a-z]?|2\.0)\b/) { die EOF; } You have the wrong version of bison in your path; currently 1.875 or 2.0 is required. Try installing End of Patch. Dave, any comment on this? errr... applied as change #25353, thanks. -- Justice is when you get what you deserve. Law is when you get what you pay for.
Re: [perl #37039] perlref documentation about optional - is too vague
On Wed, Aug 31, 2005 at 06:07:11AM -0700, japhy @ perlmonk. org wrote: In 'perlref', item #3 of 'Using References' says One more thing here. The arrow is optional between brackets sub- scripts, so you can shrink the above down to $array[$x]{foo}[0] = January; This led me to believe I could write: sub foo { ...; return @data } my $x = (foo())[0][1]; which would have the same effect as my @return = foo(); my $x = $return[0][1]; However, it's a syntax error. This can be fixed with an arrow: my $x = (foo())[0]-[1]; The problem is that (foo())[0] is NOT analogous to $array[$x]; one is a list slice, the other is a single element from an array. But the documentation does not distinguish when it says optional between brackets subscripts [sic]. I think the language there should be polished a bit. I don't see any reason not to just make it legal syntax instead: --- p/perly.y.orig 2005-06-08 01:32:12.0 -0700 +++ p/perly.y 2005-08-31 11:02:57.520643200 -0700 @@ -487,6 +487,10 @@ subscripted:star '{' expr ';' '}' | subscripted '(' ')'/* $foo-{bar}-() */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, newCVREF(0, scalar($1))); } + | '(' expr ')' '[' expr ']'/* list slice */ + { $$ = newSLICEOP(0, $5, $2); } + | '(' ')' '[' expr ']' /* empty list slice! */ + { $$ = newSLICEOP(0, $4, Nullop); } ; /* Binary operators between terms */ @@ -622,10 +626,6 @@ term : termbinop { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));} | subscripted { $$ = $1; } - | '(' expr ')' '[' expr ']'/* list slice */ - { $$ = newSLICEOP(0, $5, $2); } - | '(' ')' '[' expr ']' /* empty list slice! */ - { $$ = newSLICEOP(0, $4, Nullop); } | ary '[' expr ']' /* array slice */ { $$ = prepend_elem(OP_ASLICE, newOP(OP_PUSHMARK, 0), End of Patch. BTW, cygwin only has bison 1.875b, not the allowed 1.875 or 1.875c, but it seemed to work. I also note that Debian stable has 1.875d; would it make sense to just allow any 1.875* version? --- p/regen_perly.pl.orig 2005-05-07 04:36:14.0 -0700 +++ p/regen_perly.pl2005-08-31 11:16:02.86992 -0700 @@ -65,7 +65,7 @@ # the test below to allow that version too. DAPM Feb 04. my $version = `$bison -V`; -unless ($version =~ /\b(1\.875c?|2\.0)\b/) { die EOF; } +unless ($version =~ /\b(1\.875[a-z]?|2\.0)\b/) { die EOF; } You have the wrong version of bison in your path; currently 1.875 or 2.0 is required. Try installing End of Patch.
Re: [perl #37039] perlref documentation about optional - is too vague
On Thu, Sep 01, 2005 at 05:41:36PM -0700, Yitzchak Scott-Thoennes wrote: On Wed, Aug 31, 2005 at 06:07:11AM -0700, japhy @ perlmonk. org wrote: sub foo { ...; return @data } my $x = (foo())[0][1]; which would have the same effect as my @return = foo(); my $x = $return[0][1]; However, it's a syntax error. [...] I don't see any reason not to just make it legal syntax instead: What is my $x = (foo())[0..5][1]; supposed to mean? I know it will return (foo())[5][1] but is it a good idea to support this syntax when it looks it might mean some kind of multidimensional slice? To me it looks like map { (foo())[$_][1] } 0 .. 5; And if that syntax is ok, why not my $x = @array[0..5][1]; ? I think a warning is in order at least. We already have Multidimensional syntax %s not supported for $array[0,1][1]; -- Rick Delaney [EMAIL PROTECTED]
Re: [perl #37039] perlref documentation about optional - is too vague
On Thu, Sep 01, 2005 at 09:20:07PM -0400, Rick Delaney wrote: On Thu, Sep 01, 2005 at 05:41:36PM -0700, Yitzchak Scott-Thoennes wrote: On Wed, Aug 31, 2005 at 06:07:11AM -0700, japhy @ perlmonk. org wrote: sub foo { ...; return @data } my $x = (foo())[0][1]; which would have the same effect as my @return = foo(); my $x = $return[0][1]; However, it's a syntax error. [...] I don't see any reason not to just make it legal syntax instead: What is my $x = (foo())[0..5][1]; supposed to mean? I know it will return (foo())[5][1] but is it a good idea to support this syntax when it looks it might mean some kind of multidimensional slice? To me it looks like map { (foo())[$_][1] } 0 .. 5; I don't see any difference between your case above and my $x = (foo())[0..5]; which also doesn't warn. And if that syntax is ok, why not my $x = @array[0..5][1]; Because I couldn't conceive of a use for it? There is separate syntax for getting a single element or multiple elements of an array or hash, but only one syntax for both cases for a list. ? I think a warning is in order at least. We already have Multidimensional syntax %s not supported for $array[0,1][1]; A warning would be good, but I don't think it's necessary before applying my patch, and presumably it would also apply to @array[0..5]-[1]; whereas @array[ (0..5)[-1] ]-[1]; shouldn't warn with or without the -.
Re: [perl #37039] perlref documentation about optional - is too vague
On Thu, Sep 01, 2005 at 08:09:41PM -0700, Yitzchak Scott-Thoennes wrote: On Thu, Sep 01, 2005 at 09:20:07PM -0400, Rick Delaney wrote: On Thu, Sep 01, 2005 at 05:41:36PM -0700, Yitzchak Scott-Thoennes wrote: On Wed, Aug 31, 2005 at 06:07:11AM -0700, japhy @ perlmonk. org wrote: sub foo { ...; return @data } my $x = (foo())[0][1]; which would have the same effect as my @return = foo(); my $x = $return[0][1]; However, it's a syntax error. [...] I don't see any reason not to just make it legal syntax instead: What is my $x = (foo())[0..5][1]; supposed to mean? I know it will return (foo())[5][1] but is it a good idea to support this syntax when it looks it might mean some kind of multidimensional slice? To me it looks like map { (foo())[$_][1] } 0 .. 5; I don't see any difference between your case above and my $x = (foo())[0..5]; which also doesn't warn. And if that syntax is ok, why not my $x = @array[0..5][1]; Because I couldn't conceive of a use for it? There is separate syntax for getting a single element or multiple elements of an array or hash, but only one syntax for both cases for a list. ? I think a warning is in order at least. We already have Multidimensional syntax %s not supported for $array[0,1][1]; A warning would be good, but I don't think it's necessary before applying my patch, and presumably it would also apply to @array[0..5]-[1]; I mean (foo())[0..5]-[1]; whereas @array[ (0..5)[-1] ]-[1]; I mean ( (foo())[0..5] )[-1]-[1] shouldn't warn with or without the -. To summarize, the issue of slices of whatever kind being used in a scalar context is a separate issue from whether the - should be required before dereferences following a list slice.
Re: [perl #37039] perlref documentation about optional - is too vague
On Thu, Sep 01, 2005 at 08:09:41PM -0700, Yitzchak Scott-Thoennes wrote: On Thu, Sep 01, 2005 at 09:20:07PM -0400, Rick Delaney wrote: What is my $x = (foo())[0..5][1]; supposed to mean? I know it will return (foo())[5][1] but is it a good idea to support this syntax when it looks it might mean some kind of multidimensional slice? To me it looks like map { (foo())[$_][1] } 0 .. 5; I don't see any difference between your case above and my $x = (foo())[0..5]; which also doesn't warn. The difference is that scalar context (on the slice) in this case is imposed by the assignee but in the first case scalar context is just imposed. Changing $x to @x will only change the context of the slice in the latter case which I think is confusing. And if that syntax is ok, why not my $x = @array[0..5][1]; Because I couldn't conceive of a use for it? There is separate syntax for getting a single element or multiple elements of an array or hash, but only one syntax for both cases for a list. I couldn't conceive of one either, nor for the list slice case. Except for the single-element slice under discussion. The fact that you can't distinguish single-element from multiple-element in a slice makes it even more important to have a warning for multiple-element slices. ? I think a warning is in order at least. We already have Multidimensional syntax %s not supported for $array[0,1][1]; A warning would be good, but I don't think it's necessary before applying my patch, Agreed. and presumably it would also apply to @array[0..5]-[1]; Good point. whereas @array[ (0..5)[-1] ]-[1]; shouldn't warn with or without the -. Agreed, though that is a syntax error without the -. -- Rick Delaney [EMAIL PROTECTED]
Re: [perl #37039] perlref documentation about optional - is too vague
On Thu, Sep 01, 2005 at 08:20:17PM -0700, Yitzchak Scott-Thoennes wrote: A warning would be good, but I don't think it's necessary before applying my patch, and presumably it would also apply to @array[0..5]-[1]; I mean (foo())[0..5]-[1]; whereas @array[ (0..5)[-1] ]-[1]; I mean ( (foo())[0..5] )[-1]-[1] shouldn't warn with or without the -. Still agreed. To summarize, the issue of slices of whatever kind being used in a scalar context is a separate issue from whether the - should be required before dereferences following a list slice. Right. Sorry for the distraction. -- Rick Delaney [EMAIL PROTECTED]
[perl #37039] perlref documentation about optional - is too vague
# New Ticket Created by [EMAIL PROTECTED] # Please include the string: [perl #37039] # in the subject line of all future correspondence about this issue. # URL: https://rt.perl.org/rt3/Ticket/Display.html?id=37039 This is a bug report for perl from [EMAIL PROTECTED], generated with the help of perlbug 1.35 running under perl v5.8.4. - [Please enter your report here] In 'perlref', item #3 of 'Using References' says One more thing here. The arrow is optional between brackets sub- scripts, so you can shrink the above down to $array[$x]{foo}[0] = January; This led me to believe I could write: sub foo { ...; return @data } my $x = (foo())[0][1]; which would have the same effect as my @return = foo(); my $x = $return[0][1]; However, it's a syntax error. This can be fixed with an arrow: my $x = (foo())[0]-[1]; The problem is that (foo())[0] is NOT analogous to $array[$x]; one is a list slice, the other is a single element from an array. But the documentation does not distinguish when it says optional between brackets subscripts [sic]. I think the language there should be polished a bit. [Please do not change anything below this line] - --- Flags: category=docs severity=medium --- Site configuration information for perl v5.8.4: Configured by Debian Project at Mon Oct 25 01:52:37 EST 2004. Summary of my perl5 (revision 5 version 8 subversion 4) configuration: Platform: osname=linux, osvers=2.4.27-ti1211, archname=i386-linux-thread-multi uname='linux kosh 2.4.27-ti1211 #1 sun sep 19 18:17:45 est 2004 i686 gnulinux ' config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.4 -Dsitearch=/usr/local/lib/perl/5.8.4 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.4 -Dd_dosuid -des' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='3.3.5 (Debian 1:3.3.5-1)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt perllibs=-ldl -lm -lpthread -lc -lcrypt libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libperl.so.5.8.4 gnulibc_version='2.3.2' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Locally applied patches: --- @INC for perl v5.8.4: /home/japhy/lib/share/perl/5.8.4 /home/japhy/lib/share/perl/5.8.3 /home/japhy/lib/share/perl /etc/perl /usr/local/lib/perl/5.8.4 /usr/local/share/perl/5.8.4 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl /usr/local/lib/perl/5.8.3 /usr/local/share/perl/5.8.3 /usr/local/lib/perl/5.8.0 /usr/local/share/perl/5.8.0 . --- Environment for perl v5.8.4: HOME=/home/japhy LANG=C LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/usr/local/bin:/usr/bin:/usr/ucb:/usr/sbin:/usr/openwin/bin:/bin:/usr/local/netscape:/usr/ccs/bin:/home/japhy/bin:.:/home/japhy/ICG/home/japhy/bin:/home/japhy/perl6/ghc-6.4/bin/i386-unknown-linux PERL5LIB=/home/japhy/lib/share/perl PERL_BADLANG (unset) SHELL=/bin/tcsh