develooper Front page | perl.perl6.language | Postings from December 2008

Re: Better "sort" spec?

Thread Previous | Thread Next
From:
Patrick R. Michaud
Date:
December 13, 2008 07:32
Subject:
Re: Better "sort" spec?
Message ID:
20081213153215.GA651@pmichaud.com
On Fri, Dec 12, 2008 at 11:49:37PM -0500, Uri Guttman wrote:
> 
>      @sorted = sort {(%M{$^a}//-M $^a) <=> (%M{$^b}//-M $^b)} @unsorted;
>      @sorted = map $_[1], sort {$^a[0] <=> $^b[0]}, map [-M,$_], @unsorted;
> 
> would both become:
> 
>      @sorted = sort {-M} @unsorted;

This prompted me to go review the file test operators so I could
say "here's how it would work in Rakudo", and guess what I found:

    The advantage of the method form is that it can be used in places that
    require tighter precedence than C<~~> provides:

        sort { $^a.M <=> $^b.M }, @files

    though that's a silly example since you could just write:

        sort { .M }, @files

So it looks like at least this part of the spec already documents
the feature, which means it _is_ in the spec after all -- just not
in S29 (which is where we were looking for it).

Pm

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About