Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.9k stars 541 forks source link

"given" and extra parens #8259

Closed p5pRT closed 16 years ago

p5pRT commented 18 years ago

Migrated from rt.perl.org#38050 (status was 'resolved')

Searchable as RT38050$

p5pRT commented 18 years ago

From sorourke@cs.ucsd.edu

Created by nothanks@example.edu

According to apocalypse 4\, "given" and "when" do not rquire parens around their arguments. According to perly.y in blead\, however\, they do\, e.g. "given ($foo)" works\, but "given $foo" does not.

Perl Info ``` Flags: category=core severity=low Site configuration information for perl 5.9.3: Configured by ME at Tue Dec 27 09:48:22 PST 2005. Summary of my perl5 (revision 5 version 9 subversion 3 patch 26503) configuration: Platform: osname=darwin, osvers=8.3.0, archname=darwin-thread-multi-2level uname='darwin sean-orourkes-computer.local 8.3.0 darwin kernel version 8.3.0: mon oct 3 20:04:04 pdt 2005; root:xnu-792.6.22.obj~2release_ppc power macintosh powerpc ' config_args='' hint=recommended, useposix=true, d_sigaction=define 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 ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -I/opt/local/include', optimize='-O3 -g', cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -I/opt/local/include' ccversion='', gccversion='4.0.1 (Apple Computer, Inc. build 5247)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=4, 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 =' -L/usr/local/lib -L/opt/local/lib' libpth=/usr/local/lib /opt/local/lib /usr/lib libs=-lgdbm -ldbm -ldl -lm -lc perllibs=-ldl -lm -lc libc=/usr/lib/libc.dylib, 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 -L/opt/local/lib' Locally applied patches: DEVEL24148 @INC for perl 5.9.3: /usr/local/blead/lib/perl5/5.9.3/darwin-thread-multi-2level /usr/local/blead/lib/perl5/5.9.3 /usr/local/blead/lib/perl5/site_perl/5.9.3/darwin-thread-multi-2level /usr/local/blead/lib/perl5/site_perl/5.9.3 /usr/local/blead/lib/perl5/site_perl . Environment for perl 5.9.3: DYLD_LIBRARY_PATH (unset) HOME=/Users/ME LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.1/Libraries:/Users/ME/lib:/usr/local/lib:/sw/lib:/opt/local/lib LOGDIR (unset) PATH=/Users/ME/bin:/usr/local/bin:/opt/local/bin:/usr/sbin:/sbin:/sw/sbin:/sw/bin:/usr/bin:/bin:/usr/local/teTeX/bin/powerpc-apple-darwin-current:/usr/X11R6/bin PERL_BADLANG (unset) PERL_INLINE_JAVA_JNI=1 SHELL=/bin/zsh ```
p5pRT commented 18 years ago

From @ysth

On Tue\, Dec 27\, 2005 at 11​:15​:12AM -0800\, Sean O'Rourke wrote​:

According to apocalypse 4\, "given" and "when" do not rquire parens around their arguments. According to perly.y in blead\, however\, they do\, e.g. "given ($foo)" works\, but "given $foo" does not.

See​:

http​://groups.google.com/groups?threadm=20051209131351.GA1365@​rpc142.cs.man.ac.uk

p5pRT commented 18 years ago

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

p5pRT commented 18 years ago

From sorourke@cs.ucsd.edu

"Yitzchak Scott-Thoennes via RT" \perlbug\-followup@​perl\.org writes​:

See​:

http​://groups.google.com/groups?threadm=20051209131351.GA1365@​rpc142.cs.man.ac.uk

Thanks\, and (perhaps) disregard my previous message. It might be worth adding a test that highlights *why* the parens are required in Perl 5. Apparently none of the current tests do so.

/s

p5pRT commented 18 years ago

From sorourke@cs.ucsd.edu

For what it's worth\, this patch appears to fix it and passes all the current tests.

/s

p5pRT commented 18 years ago

From sorourke@cs.ucsd.edu

perly.diff ```diff --- perly.y 2005-12-19 08:28:40.000000000 -0800 +++ my-perly.y 2005-12-27 10:58:56.000000000 -0800 @@ -211,9 +211,9 @@ cond : IF '(' remember mexpr ')' mblock ; /* Cases for a switch statement */ -case : WHEN '(' remember mexpr ')' mblock - { $$ = block_end($3, - newWHENOP($4, scope($6))); } +case : WHEN remember mexpr mblock + { $$ = block_end($2, + newWHENOP($3, scope($4))); } | DEFAULT block { $$ = newWHENOP(0, scope($2)); } ; @@ -272,12 +272,12 @@ loop : label WHILE '(' remember texpr ') ; /* Switch blocks */ -switch : label GIVEN '(' remember mydefsv mexpr ')' mblock +switch : label GIVEN remember mydefsv mexpr mblock { PL_copline = (line_t) $2; - $$ = block_end($4, + $$ = block_end($3, newSTATEOP(0, $1, - newGIVENOP($6, scope($8), - (PADOFFSET) $5) )); } + newGIVENOP($5, scope($6), + (PADOFFSET) $4) )); } ; /* determine whether there are any new my declarations */ ```
p5pRT commented 18 years ago

From @ysth

On Tue\, Dec 27\, 2005 at 11​:46​:52AM -0800\, Sean O'Rourke wrote​:

"Yitzchak Scott-Thoennes via RT" \perlbug\-followup@​perl\.org writes​:

See​:

http​://groups.google.com/groups?threadm=20051209131351.GA1365@​rpc142.cs.man.ac.uk

Thanks\, and (perhaps) disregard my previous message. It might be worth adding a test that highlights *why* the parens are required in Perl 5. Apparently none of the current tests do so.

Any differences from perl6 should be documented\, if they are not already\, so bug-minders\, please don't close this yet.

p5pRT commented 18 years ago

From robin@cpan.org

According to apocalypse 4\, "given" and "when" do not rquire parens around their arguments. According to perly.y in blead\, however\, they do\, e.g. "given ($foo)" works\, but "given $foo" does not.

It's worth noting that\, in Perl 6\, "if" and "while" do not require parens around their arguments either.

The fundamental problem is this​: in Perl 6\, whitespace is forbidden in certain places where it is permitted in Perl 5\, which makes it possible to disambiguate between C\<if %foo { ... }> and C\<if %foo{ ... } { ... }>\, for example.

If the parentheses are made optional in Perl 5 -- or at least if this is done in the naive way\, as in Sean's patch -- an expression such as

  given $foo { print "Oh look! It's foo.\n" }

would be parsed as

  given ($foo{ print "Oh look! It's foo.\n" })

and then throw a syntax error because the expression is not followed by a block. (That's what happens when your parse is determined by just one token of lookahead!)

Of course this difficulty is not necessarily insurmountable\, and one can imagine ways that it might be overcome. But I think this is misguided thinking​: if we are to make the parentheses optional here\, we should also do so for C\ and C\. But why would we? It would bring no real benefit. (If we imported a feature from Python\, would we make it indentation-scoped?)

Robin

PS. I agree that differences from Perl 6 should be documented   somewhere. I'll send a patch.

p5pRT commented 16 years ago

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'