develooper Front page | perl.perl6.language | Postings from February 2004

Re: The Sort Problem

Thread Previous | Thread Next
From:
Joe Gottman
Date:
February 15, 2004 15:41
Subject:
Re: The Sort Problem
Message ID:
012601c3f41d$8604db40$e58f8445@carolina.rr.com

----- Original Message ----- 
From: "Damian Conway" <damian@conway.org>
To: "Larry Wall" <larry@wall.org>
Cc: "Perl 6 Language" <perl6-language@perl.org>
Sent: Sunday, February 15, 2004 5:59 PM
Subject: [perl] Re: The Sort Problem


> Here's a proposed syntax and semantics for C<sort> that tries to preserve
the
> (excellent) features of Uri's "on the right track" proposal whilst
integrating
> it into the Perl 6 design without multiplying entities (especially
colons!)
> unnecessarily.
>
> Suppose C<sort>'s signature is:
>
>      type KeyExtractor ::= Code(Any) returns Any;
>
>      type Comparator   ::= Code(Any, Any) returns Int;
>
>      type Criterion    ::= KeyExtractor
>                          | Comparator
>                          | Pair(KeyExtractor, Comparator)
>                          ;
>
>      type Criteria     ::= Criterion
>                          | Array of Criterion
>                          ;
>
>      multi sub *sort(Criteria ?$by = {$^a cmp $^b}, *@data) {...}
>

   If we use this signature, won't the code
        sort ('foo', 'bar', 'glarch');

attempt to use the first parameter as a Criteria?  Since sort has to be a
multi sub anyhow, why don't we do

    multi sub *sort(Criteria $by : *@data) {...}
    multi sub *sort( : *@data) { ...} # returns sort {$^a cmp $^b} @data

Joe Gottman



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