On Tue, Sep 19, 2000 at 07:29:56PM -0000, Perl6 RFC Librarian wrote:

> This RFC proposes a builtin C<reduce> function, modelled after Graham Barr's
> C<reduce> subroutine from builtin.pm

Please refer to List::Util rather than builtin.pm

the module name was changed as many did not like the name builting, as it was not.

Graham.

> In all cases, the elements of the list are lazily evaluated. That is,
> any element of the list that is not a literal value is only evaluated
> when that element is passed to (and actually used by) the reduction
> subroutine.

Should lists be lazy by default ? I would suggest that is a separate
language issue then reduce and reduce should follow what all other
list operators do.

> If the original list has no elements, C<reduce> immediately throws an
> exception.

What do you mean by exception, die ? No other builtin dies like that at
runtime. Perhaps a return of undef would be more like other operators.

> If the original list has a single element, that element is
> immediately returned (without ever calling the reduction subroutine).
> Otherwise, in a scalar context, the result of the final reduction call
> is the result returned by C<reduce>. In a list context, a list of all
> the interim values, plus the final value, would be returned.

Um, if it is returning a list then it is not reducing, is it ?

> If the reduction subroutine is ever terminated by a call to C<last>, the
> enclosing C<reduce> immediately returns the last reduction value -- or
> list of partial values -- to that point. If the C<last> occurs during
> the first reduction, an exception is thrown.

Again, no other builting currently throws an exception. If throwing an
exception is to become the norm then that should be a separate RFC suggesting
that builtins throw exceptions, but reduce should do what others do.

Graham.

Reply via email to