Skip to content

sort SUBNAME LIST #7376

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

Closed
p5pRT opened this issue Jun 19, 2004 · 6 comments
Closed

sort SUBNAME LIST #7376

p5pRT opened this issue Jun 19, 2004 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 19, 2004

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

Searchable as RT30377$

@p5pRT
Copy link
Author

p5pRT commented Jun 19, 2004

From [email protected]

Created by [email protected]

perl -wle 'sub foo { return 1..5} print sort foo(8)'
8

while a bit annoying (I wanted to sort the result of foo applied to 8),
this is actually what is documented as the
sort SUBNAME LIST
form of sort. foo is the subname and there is one value to be sorted​: 8

5.6.1 this will reportedly behaves the same (I don't have a 5.6.1 anymore)

More interesting​:
perl -wle 'sub foo { return 1..5} print sort(foo(8))'
12345

I see nothing in the sort docs that would make me expect a change in
behaviour here by just adding parenthesis.
(Nor does it in real indirect object cases like print(STDERR "foo"))

And on 5.6.1 it actually didn't matter​:
perl -wle 'sub foo { return 1..5} print sort(foo(8))'
Unquoted string "foo" may clash with future reserved word at -e line 1.
8

So you get an extra warning and it behaves the same as without the
parenthesis. For both things I think that the 5.6.1 behaviour was the
right one. In fact, I'd also have expected the unquoted string warning
for the case without parenthesis, but it seems 5.6.1 doesn't do that.

If you don't agree with me that these are bugs, this behaviour should at
least be documented.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.8.4:

Configured by ton at Thu Jun  3 13:28:19 CEST 2004.

Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
  Platform:
    osname=linux, osvers=2.6.5, archname=i686-linux-64int-ld
    uname='linux quasar 2.6.5 #8 mon apr 5 05:41:20 cest 2004 i686 gnulinux '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=define
    usemymalloc=y, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -fomit-frame-pointer',
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='3.4.0 20031231 (experimental)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, 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=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
    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:
    /usr/lib/perl5/5.8.4/i686-linux-64int-ld
    /usr/lib/perl5/5.8.4
    /usr/lib/perl5/site_perl/5.8.4/i686-linux-64int-ld
    /usr/lib/perl5/site_perl/5.8.4
    /usr/lib/perl5/site_perl
    .


Environment for perl v5.8.4:
    HOME=/home/ton
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/ton/bin.Linux:/home/ton/bin:/home/ton/bin.SampleSetup:/opt/schily/bin:/usr/local/bin:/usr/local/sbin:/home/oracle/product/9.0.1/bin:/usr/local/ar/bin:/usr/games/bin:/usr/X11R6/bin:/usr/share/bin:/usr/bin:/usr/sbin:/bin:/sbin:.
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2005

From @schwern

[perl-5.8.0@​ton.iguana.be - Sat Jun 19 11​:06​:22 2004]​:

perl -wle 'sub foo { return 1..5} print sort foo(8)'
8

while a bit annoying (I wanted to sort the result of foo applied to
8),
this is actually what is documented as the
sort SUBNAME LIST
form of sort. foo is the subname and there is one value to be sorted​:
8

5.6.1 this will reportedly behaves the same (I don't have a 5.6.1
anymore)

5.6.2 does.

More interesting​:
perl -wle 'sub foo { return 1..5} print sort(foo(8))'
12345

I see nothing in the sort docs that would make me expect a change in
behaviour here by just adding parenthesis.
(Nor does it in real indirect object cases like print(STDERR "foo"))

I don't think print is the right analogy here. map and grep have the
closest interface to sort.

So you get an extra warning and it behaves the same as without the
parenthesis. For both things I think that the 5.6.1 behaviour was the
right one. In fact, I'd also have expected the unquoted string warning
for the case without parenthesis, but it seems 5.6.1 doesn't do that.

If you don't agree with me that these are bugs, this behaviour should
at
least be documented.

I don't know if its a bug so much as an ambiguity made espcially tricky
by its reliance on whitespace to DWIM. Changing the behavior to this
would seem to be more like folks would expect.

  sort foo(8) # call foo(8) and hand the results to sort
  sort foo (8) # use foo() as the sort routine to sort the list (8).

And before the C<func (arg)> style camp objects, its not working
properly for that style now anyway.

@p5pRT
Copy link
Author

p5pRT commented Jul 18, 2005

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

@p5pRT
Copy link
Author

p5pRT commented Nov 1, 2006

From [email protected]

Created by [email protected]

I believe that "sort fn( EXPR, EXPR )" is mistakenly being parsed
as "sort fn ( EXPR, EXPR )". The following code produces these results​:

Unexpected​: Key2 Key1 KeyB KeyD KeyC KeyA KeyB KeyC
MoreLikeIt​: Key1 Key2 KeyA KeyB KeyC KeyD

#--------------------- snip snip snip ------------------
  #!/usr/bin/env perl5
  use warnings;
  use strict;
 
  my %data = ( Key1 => { KeyA => 1,
  KeyB => 2,
  KeyC => 3 },
  Key2 => { KeyB => 2,
  KeyC => 3,
  KeyD => 4 },
  );
 
  my @​unexpected = sort uniq( keys( %data ),
  map{ keys %$_ } values %data );
 
  my @​moreLikeIt = sort( uniq( keys( %data ),
  map{ keys %$_ } values %data ));
 
  print "Unexpected​: @​unexpected\nMoreLikeIt​: @​moreLikeIt\n";
 
 
  sub uniq {
  my %hash;
 
  @​hash{ @​_ } = ();
 
  return keys %hash;
  }
#--------------------- snip snip snip ------------------

I believe that the "sort SUBNAME LIST" interpretation is incorrect because

  1) 'perldoc perlop', in terms "Terms and List Operators (Leftward)"
  section says "function whose arguments are parenthesized" has the
  highest precedence in Perl. Not being able to break "fn" and
  "( EXPR, EXPR )" into separate productions leaves no possible
  interpretation other than "sort LIST" for "sort fn( EXPR, EXPR )".

  2) If I had wanted a "sort fn( EXPR, EXPR )" to be parsed as
  "sort SUBNAME LIST", I should be required to use unary '+' as in​:
  "sort fn +( EXPR, EXPR )".

  3) schwern says so. :-)

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.8.8:

Configured by paull at Tue May 23 11:12:33 PDT 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.4.21-37.el, archname=i686-linux
    uname='linux lxcvirt.cv.hp.com 2.4.21-37.el #1 wed sep 7 13:35:21 edt 2005 i686 i686 i386 gnulinux '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/include/gdbm'
    ccversion='', gccversion='3.2.3 20030502 (Red Hat Linux 3.2.3-53)', 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/lib -L/usr/lib'
    libpth=/lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared -L/lib -L/usr/lib'

Locally applied patches:
    


@INC for perl v5.8.8:
    /apps/perl-5.8.8/2.4X86-32/lib/5.8.8/i686-linux
    /apps/perl-5.8.8/2.4X86-32/lib/5.8.8
    /apps/perl-5.8.8/2.4X86-32/lib/site_perl/5.8.8/i686-linux
    /apps/perl-5.8.8/2.4X86-32/lib/site_perl/5.8.8
    /apps/perl-5.8.8/2.4X86-32/lib/site_perl
    .


Environment for perl v5.8.8:
    HOME=/home/paull
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/apps/perl-5.8.8/2.4X86-32/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/apps/perl5/2.4X86-32/bin:/apps/perl5/2.4X86-32/bin:/home/paull/bin:/sdg/bin:.
    PERL_BADLANG (unset)
    SHELL=/usr/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jun 28, 2009

From [email protected]

$ perl-5.6.1 -wle 'sub foo { return 1..5} print sort(foo(8))'
Unquoted string "foo" may clash with future reserved word at -e line 1.
8

$ perl-5.8.0 -wle 'sub foo { return 1..5} print sort(foo(8))'
12345

Bisect​:
----Program----
#!/usr/bin/perl -l

sub foo { return 1..5 }
print sort(foo(8))

----Output of ...l/pxZYtEz/perl-5.7.0@​8238/bin/perl----
8

----EOF ($?='0')----
----Output of ...l/pw7q1Jw/perl-5.7.0@​8239/bin/perl----
12345

----EOF ($?='0')----
Need a perl between 8238 and 8239

http​://perl5.git.perl.org/perl.git/commit/
f067069
author Simon Cozens <simon@​netthink.co.uk>
  Wed, 27 Dec 2000 14​:12​:44 +0000 (14​:12 +0000)
committer Jarkko Hietaniemi <jhi@​iki.fi>
  Thu, 28 Dec 2000 22​:37​:45 +0000 (22​:37 +0000)
commit f067069
tree 8bbec927d4422331c4ad492ac366b541d861526d tree | snapshot
parent a5de305 commit | diff

Re​: [ID 19991001.003] sort(sub(arg)) misparsed as sort sub args
Message-ID​: <20001227141244.A13344@​deep-dark-truthful-
mirror.perlhacker.org>

p4raw-id​: //depot/perl@​8239

This was an intended change of behaviour. See [perl #1549].

A patch to update the documentation and add more examples has been
submitted in [perl #54040].

=> Setting this one to resolved.

@p5pRT
Copy link
Author

p5pRT commented Jun 28, 2009

[email protected] - Status changed from 'open' to 'resolved'

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