On Wed, Sep 20, 2000 at 05:08:26AM -0000, Perl6 RFC Librarian wrote:
> =head1 ABSTRACT
> 
> This RFC proposes a built-in C<reduce> function, modelled after Graham
> Barr's C<reduce> subroutine from the List::Utils module (a.k.a. The
> Module Formerly Known As builtin.pm).


:-)

> If fewer than N-1 elements would be available for the final reduction
> call, a exception is thrown. Note that this exception could be thrown
> I<before> the reduction begins, by determining the total number of elements
> to be reduced (I<R>) and the number of elements to be processed on each
> reduction step (I<r>) and testing whether the resulting number of steps --
> (I<R>-I<r>)/(I<r>-1) -- is integral.

This would preclude the list from ever being lazy as you will have to expand
it. I would also not that

  @array = (1,2,3);
  %hash = @array;

just gives a warning and the element 3 gets undef. Similar has been suggested
for

  for my($x,$y) ( @array) { ... }

would give a warning on the final iteration and $y would be undef.

I would suggest

I there is 1 element, it is returned. If there are fewer than N elements
for the first reducetion, or N-1 elements for the final reduction, then
a warning is given and undef is passed for the missing elements to the
reduction call.

This does not force exception handling on the user and leaves what to do
upto them.

Graham.

Reply via email to