develooper Front page | perl.perl6.language | Postings from October 2005

Re: Look-ahead arguments in for loops

Thread Previous | Thread Next
Luke Palmer
October 1, 2005 13:22
Re: Look-ahead arguments in for loops
Message ID:
On 10/1/05, John Macdonald <> 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.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About