On 10/1/05, John Macdonald <[EMAIL PROTECTED]> wrote:
> I forget what the final choice was for syntax for the reduce
> operator (it was probably even a different name from reduce -
> that's the APL name), but it would be given a list and an
> operator and run as:
>     my $running = op.identity;
>     $running = $running op $_ for @list;
> So, to get a loop body that knows the previous value, you
> define an operator whose identity is the initial value of the
> list and reduce the rest of the list.

And that was never quite resolved.  The biggest itch was with
operators that have no identity, and operators whose codomain is not
the same as the domain (like <, which takes numbers but returns

Anyway, that syntax was

    $sum = [+] @items;

And the more general form was:

    $sum = reduce { $^a + $^b } @items;

Yes, it is called reduce, because "foldl" is a miserable name.


Reply via email to