On Fri, Sep 30, 2005 at 08:39:58PM -0600, Luke Palmer wrote:
> Incidentally, the undef problem just vanishes here (being replaced by
> another problem).

Which reminds me that this same issue came up a while ago in a
different guise.  There was a long discussion about the reduce
functionality that takes an array and applies an operator to
each value and the previously collected result.  (Much of the
discussion was on determining what the identity value for an
operator was to initialize the "previous result".)  Most of
the time that you want a loop that remembers the "previous"
value, it can be equally well expressed an a reduction of the
series of value using an customer defined operator.

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.


-- 

Reply via email to