Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion dynamic arguments (was: The Sort Problem)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
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. Listen and type the numbers you hear
 
Jonathan Lang  
View profile  
 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:
> > I've been thinking about this problem which comes up in my code a lot:

> >    @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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.