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

Re: dynamic arguments (was: The Sort Problem)

Thread Previous | Thread Next
From:
Jonathan Lang
Date:
February 12, 2004 20:57
Subject:
Re: dynamic arguments (was: The Sort Problem)
Message ID:
20040213045714.42092.qmail@web40806.mail.yahoo.com
Luke Palmer wrote:
> Jonathan Lang writes:
> > How about including something similar to <==, but which binds the
> > elements of the list to the various positional parameters?  For 
> > instance: 
> > 
> >   @sorted = sort {infix:<=> args map {$_.foo('bar').compute}, 
> >                   $^a, $^b } @unsorted; 
> > 
> > Where
> > 
> >   @x = $a, $b, $c; 
> >   routine args @x; 
> > 
> > is equivelent to
> > 
> >   routine $a, $b, $c;
> 
> We already have that.  It's spelled:
> 
>     routine *@x;
> 
> Or
> 
>     routine * <== @x;

Then you've got your solution:

  @sorted = sort {infix:<=> * map {$_.foo('bar').compute}, $^a, $^b }
            @unsorted; 

or

  @sorted = sort {($^a, $^b) ==>
                  map {$_.foo('bar').compute} ==>
                  infix:<=> * } @unsorted; 

=====
Jonathan "Dataweaver" Lang

__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

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