Graham Barr wrote: > On Tue, Aug 15, 2000 at 02:03:12PM +1000, Jeremy Howard wrote: > > The PDL team are now examining how to incorporate these kinds of features > > into perl 6. I'm also interested in seeing how to implement things like > > (from RFC 82) > > > > <quote> > > @b = (1,2,3); > > @c = (2,4,6); > > @d = (-2,-4,-6); > > $sum = reduce ^_+^_, @b * @c + @d; > > Well if operators were made to return iterators in a list context > then I can see that that would work. For example > > @b * @c would create an iterator which would return the > product of the elements in turn. <iter> + @d would > be an iterator that return the sum of the next value from > <iter> and the next from @d. This final iterator is > what is passed to reduce. redice calls <iter>->next to > get the next value. > Actually, I was thinking that they should return a lazily generated list, something like what's described in RFC 81: http://tmtowtdi.perl.org/rfc/81.pod The problem with thinking of it as an iterator is that random access becomes a real pain (although it doesn't matter if it's only used in reduce() of course). For instance, indexing the list using a slice (to use it as a matrix) would calculate every element of the list even although only every nth element would be required. Another example would be where the colour of just one pixel of a manipulated image was required--clearly the entire the image should not be generated in this case.