The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Message from discussion dynamic arguments (was: The Sort Problem)

From:
To:
Cc:
Followup To:
Subject:
 Validation: For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon.

More options Feb 12 2004, 11:48 pm
Newsgroups: perl.perl6.language
From: dataweave...@yahoo.com (Jonathan Lang)
Date: Thu, 12 Feb 2004 20:14:40 -0800 (PST)
Local: Thurs, Feb 12 2004 11:14 pm
Subject: dynamic arguments (was: The Sort Problem)

Jonathan Lang wrote:
> Luke Palmer wrote:

> >    @sorted = sort { \$^a.foo('bar').compute <=> \$^b.foo('bar').compute}
> >                 @unsorted;

> > Often the expressions on each side are even longer than that.  But one
> > thing remains:  both sides are exactly the same, substitute a \$^b for
> > a \$^a.

> The problem, then, isn't specific to sort; it happens any time that you
> find yourself needing to do the same things to multiple arguments.  As
> such, the solution ought to be more general than just sort.

> You're looking for something to the effect of:

>   @sorted = sort { parameters(\$^a <=> \$^b).foo('bar').compute }

> That is, you need a way to factor C<.foo('bar').compute> out from each
> of the arguments that it applies to.  For list arguments, this is
> straightforward: pipe the list arguments through a map before you pipe
> them into the routine.  A similar approach could be used with named
> arguments.  The problem comes when you deal with positional arguments.

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;

=====
Jonathan "Dataweaver" Lang

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