> On Tue, Aug 01, 2000 at 11:59:22AM -0400, Chaim Frenkel wrote:
   > >  Reduce          (e.g. $x = reduce { sum } @list;
   > 
   > I mentioned this to Larry on the Friday after the conference
   > and his response was that he did think about it originally but
   > 
   >   $sum = reduce + @list; # assuming I got the verbal->syntax translation right
   > 
   > was not easy todo. I was not even thinking of that but just some like
   > sort where we have $a and $b (ala the List::Util::reduce function)
   > But I must admit, this syntax would be nice for some operators

I had a paper on that.

The solution (which I with RFC RSN) is to provide a simple mechanism for
generating higher-order functions.

The one I proposed in the switch statement paper
(http://www.csse.monash.edu.au/~damian/TPC/2000/switch/paper.txt) was
the __ meta-variable. Used in place of an operand or an argument, it
creates an anonymous subroutine that evaluates the corresponding
operation or subroutine, substituting elements of @_ for the
meta-variables.

In other words:

        $incr = __ + 1;

is exactly equivalent to:

        $incr = sub { $_[0] + 1 }

So you can additively reduce a list like  so:

        $sum = reduce __+__, @list;

There's a protoype implementation available as part of the switch.pm module,
which will hit the CPAN some time this week (assuming I don't actually
*die* of jet-lag :-)

Damian

Reply via email to