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

sort() parsing error (5.005_02) #1840

Closed
p5pRT opened this issue Apr 14, 2000 · 8 comments
Closed

sort() parsing error (5.005_02) #1840

p5pRT opened this issue Apr 14, 2000 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 14, 2000

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

Searchable as RT3103$

@p5pRT
Copy link
Author

p5pRT commented Apr 14, 2000

From jeffp@crusoe.net

Created by jeffp@crusoe.net

  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? :(

Perl Info


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





@p5pRT
Copy link
Author

p5pRT commented Apr 14, 2000

From @tamias

On Fri, Apr 14, 2000 at 10​:47​:06PM -0400, Jeff Pinyan wrote​:

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

@p5pRT
Copy link
Author

p5pRT commented Apr 14, 2000

From [Unknown Contact. See original ticket]

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.

@p5pRT
Copy link
Author

p5pRT commented Apr 14, 2000

From @tamias

On Fri, Apr 14, 2000 at 10​:58​:58PM -0400, Jeff Pinyan wrote​:

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

@p5pRT
Copy link
Author

p5pRT commented Apr 15, 2000

From [Unknown Contact. See original ticket]

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()); ?

I find it silly. Maybe because
I'm in a grumpy mood, but I find it silly.

@p5pRT
Copy link
Author

p5pRT commented Apr 15, 2000

From @tamias

On Sat, Apr 15, 2000 at 01​:08​:39PM +0100, Nick Ing-Simmons wrote​:

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

@p5pRT
Copy link
Author

p5pRT commented Apr 15, 2000

From [Unknown Contact. See original ticket]

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 :-)

--
Nick Ing-Simmons

@p5pRT
Copy link
Author

p5pRT commented Apr 15, 2000

From [Unknown Contact. See original ticket]

In article <38F89263.B19A297F@​fdesar.net>,
  François Désarménien <francois@​fdesar.net> writes​:

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).

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

No branches or pull requests

1 participant