Skip Menu |
Report information
Id: 3103
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: jeffp [at] crusoe.net
Cc:
AdminCc:

Operating System: Solaris
PatchStatus: (no value)
Severity: low
Type: library
Perl Version: 5.005_02
Fixed In: (no value)



Date: Fri, 14 Apr 2000 22:47:06 -0400 (EDT)
From: Jeff Pinyan <jeffp [...] crusoe.net>
To: perlbug [...] perl.com
Subject: sort() parsing error (5.005_02)
Download (untitled) / with headers
text/plain 2.3k
(My perlbug is b0rken) This is a bug report for perl from jeffp@crusoe.net, generated with the help of perlbug 1.26 running under perl 5.00502. ----------------------------------------------------------------- [Please enter your report here] sub foo { return (1,20,2,30) } @a = sort foo(); print @a; # empty list Perl parses this as @a = sort foo (); That is, sorting the empty list by some function. What's that status of this in 5.6? And is this desireable? :( [Please do not change anything below this line] ----------------------------------------------------------------- --- Site configuration information for perl 5.00502: Configured by jeffp at Wed Mar 24 18:23:10 EST 1999. Summary of my perl5 (5.0 patchlevel 5 subversion 2) configuration: Platform: osname=solaris, osvers=2.5.1, archname=sun4-solaris uname='sunos friday 5.5.1 generic_103640-22 sun4m sparc sunw,sparcstation-5 ' hint=recommended, useposix=true, d_sigaction=define usethreads=undef useperlio=undef d_sfio=undef Compiler: cc='/usr/local/bin/gcc', optimize='-O', gccversion=2.7.2.3 cppflags='-I/usr/local/include' ccflags ='-I/usr/local/include' stdchar='unsigned char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 alignbytes=8, usemymalloc=y, prototype=define Linker and Libraries: ld='/usr/local/bin/gcc', ldflags =' -L/usr/local/lib -L/opt/gnu/lib' libpth=/usr/local/lib /opt/gnu/lib /lib /usr/lib /usr/ccs/lib libs=-lsocket -lnsl -ldb -ldl -lm -lc -lcrypt libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib -L/opt/gnu/lib' Locally applied patches: --- @INC for perl 5.00502: /usr/local/lib/perl5/5.00502/sun4-solaris /usr/local/lib/perl5/5.00502 /usr/local/lib/perl5/site_perl/5.005/sun4-solaris /usr/local/lib/perl5/site_perl/5.005 . --- Environment for perl 5.00502: HOME=/home/jeffp LANG (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/usr/local/bin:/usr/bin:/usr/ucb:/usr/sbin:/usr/openwin/bin:/bin:/crusoe/appl/bin:/usr/local/netscape:/usr/ccs/bin:.:/home/jeffp/utils:/home/jeffp/local/bin PERL_BADLANG (unset) SHELL=/bin/tcsh
Date: Fri, 14 Apr 2000 22:54:28 -0400
From: Ronald J Kimball <rjk [...] linguist.dartmouth.edu>
To: japhy [...] pobox.com
Cc: perl5-porters [...] perl.org
Subject: Re: [ID 20000414.008] sort() parsing error (5.005_02)
Download (untitled) / with headers
text/plain 459b
On Fri, Apr 14, 2000 at 10:47:06PM -0400, Jeff Pinyan wrote: Show quoted text
> sub foo { return (1,20,2,30) } > @a = sort foo(); > print @a; # empty list > > Perl parses this as > > @a = sort foo (); > > That is, sorting the empty list by some function. What's that status of > this in 5.6? And is this desireable? :( >
That is the expected behavior. =item sort SUBNAME LIST Disambiguate if that's not what you meant. sort +foo(); sort &foo(); Ronald
Date: Fri, 14 Apr 2000 22:58:58 -0400 (EDT)
From: Jeff Pinyan <jeffp [...] crusoe.net>
To: Ronald J Kimball <rjk [...] linguist.dartmouth.edu>
Cc: perl5-porters [...] perl.org
Subject: Re: [ID 20000414.008] sort() parsing error (5.005_02)
Download (untitled) / with headers
text/plain 391b
On Apr 14, Ronald J Kimball said: Show quoted text
>On Fri, Apr 14, 2000 at 10:47:06PM -0400, Jeff Pinyan wrote: >
>> @a = sort foo ();
> >Disambiguate if that's not what you meant. > >sort +foo(); >sort &foo();
Yes, I know that. But sorting the EXPLICITLY empty list with a function -- this isn't SLIGHTLY counterintuitive? I find it silly. Maybe because I'm in a grumpy mood, but I find it silly.
Date: Fri, 14 Apr 2000 23:04:41 -0400
From: Ronald J Kimball <rjk [...] linguist.dartmouth.edu>
To: japhy [...] pobox.com
Cc: perl5-porters [...] perl.org
Subject: Re: [ID 20000414.008] sort() parsing error (5.005_02)
Download (untitled) / with headers
text/plain 659b
On Fri, Apr 14, 2000 at 10:58:58PM -0400, Jeff Pinyan wrote: Show quoted text
> On Apr 14, Ronald J Kimball said: >
> >On Fri, Apr 14, 2000 at 10:47:06PM -0400, Jeff Pinyan wrote: > >
> >> @a = sort foo ();
> > > >Disambiguate if that's not what you meant. > > > >sort +foo(); > >sort &foo();
> > Yes, I know that. But sorting the EXPLICITLY empty list with a function > -- this isn't SLIGHTLY counterintuitive? I find it silly. Maybe because > I'm in a grumpy mood, but I find it silly.
Sorry, fixing it would be more counterintuitive: sort foo (); # sorts &foo() with default comparison function sort foo (1); # sorts (1) with &foo as comparison function Ronald
Subject: Re: [ID 20000414.008] sort() parsing error (5.005_02)
To: japhy [...] pobox.com
Cc: Ronald J Kimball <rjk [...] linguist.dartmouth.edu>, perl5-porters [...] perl.org
From: Nick Ing-Simmons <nick [...] ing-simmons.net>
Date: Sat, 15 Apr 2000 13:08:39 +0100
Download (untitled) / with headers
text/plain 680b
Jeff Pinyan <japhy@pobox.com> writes: Show quoted text
>On Apr 14, Ronald J Kimball said: >
>>On Fri, Apr 14, 2000 at 10:47:06PM -0400, Jeff Pinyan wrote: >>
>>> @a = sort foo ();
>> >>Disambiguate if that's not what you meant. >> >>sort +foo(); >>sort &foo();
> >Yes, I know that. But sorting the EXPLICITLY empty list with a function >-- this isn't SLIGHTLY counterintuitive?
Perl's parser is one of Yacc family - which are LALR(1) i.e. one symbol look ahead. So when looking a 'sort' 'foo' _ '(' ')' ';' it can only look at the opening '(' and cannot tell list is empty. Why not write it as sort (foo()); ? Show quoted text
>I find it silly. Maybe because >I'm in a grumpy mood, but I find it silly.
Date: Sat, 15 Apr 2000 09:32:31 -0400
From: Ronald J Kimball <rjk [...] linguist.dartmouth.edu>
To: Nick Ing-Simmons <nick [...] ing-simmons.net>
Cc: japhy [...] pobox.com, perl5-porters [...] perl.org
Subject: Re: [ID 20000414.008] sort() parsing error (5.005_02)
Download (untitled) / with headers
text/plain 906b
On Sat, Apr 15, 2000 at 01:08:39PM +0100, Nick Ing-Simmons wrote: Show quoted text
> Jeff Pinyan <japhy@pobox.com> writes:
> >On Apr 14, Ronald J Kimball said: > >
> >>On Fri, Apr 14, 2000 at 10:47:06PM -0400, Jeff Pinyan wrote: > >>
> >>> @a = sort foo ();
> >> > >>Disambiguate if that's not what you meant. > >> > >>sort +foo(); > >>sort &foo();
> > > >Yes, I know that. But sorting the EXPLICITLY empty list with a function > >-- this isn't SLIGHTLY counterintuitive?
> > Perl's parser is one of Yacc family - which are LALR(1) i.e. one > symbol look ahead. So when looking a 'sort' 'foo' _ '(' ')' ';' > it can only look at the opening '(' and cannot tell > list is empty. > > Why not write it as sort (foo()); ?
Because that's still parsed as sorting the empty list with &foo as the comparison function. :) But why is sort ((foo())); a syntax error (at least in 5.005_03 - haven't checked 5.6.0)? Ronald
Date: Sat, 15 Apr 2000 18:01:39 +0200
From: =?iso-8859-1?Q?Fran=E7ois=20D=E9sarm=E9nien?= <francois [...] fdesar.net>
To: Nick Ing-Simmons <nick [...] ing-simmons.net>
Cc: japhy [...] pobox.com, Ronald J Kimball <rjk [...] linguist.dartmouth.edu>, perl5-porters [...] perl.org
Subject: Re: [ID 20000414.008] sort() parsing error (5.005_02)
Download (untitled) / with headers
text/plain 361b
Nick Ing-Simmons wrote: Show quoted text
> > Perl's parser is one of Yacc family - which are LALR(1) i.e. one > symbol look ahead. So when looking a 'sort' 'foo' _ '(' ')' ';' > it can only look at the opening '(' and cannot tell > list is empty.
But you can add black magic to the lexer to handle those cases, although it might be convoluted :-) Show quoted text
> > -- > Nick Ing-Simmons
Subject: Re: [ID 20000414.008] sort() parsing error (5.005_02)
Date: 16 Apr 2000 01:45:36 GMT
From: thospel [...] mail.dma.be (Ton Hospel)
To: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 771b
In article <38F89263.B19A297F@fdesar.net>, François Désarménien <francois@fdesar.net> writes: Show quoted text
> Nick Ing-Simmons wrote:
>> >> Perl's parser is one of Yacc family - which are LALR(1) i.e. one >> symbol look ahead. So when looking a 'sort' 'foo' _ '(' ')' ';' >> it can only look at the opening '(' and cannot tell >> list is empty.
> > But you can add black magic to the lexer to handle those cases, > although it might be convoluted :-) >
Well, one thing that might be a good idea is to have perl generate a warning if you call sort on a constant empty list since the result can hardly be surprising to the programmer. (I wanted to say list of constants, but I can imagine a weird program where the sort function is the variable, so that could even make sense).


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org