Hi
I'm sure I'm missing something fairly fundamental, but could someone
shed more light on the example:
# reduce list three-at-a-time
$sum_of_powers = reduce { $^partial_sum + $^x ** $^y } 0, @xs_and_ys;
specifically what is being iterated over, what gets bound and what does
it return?
I thought I understood this, the reduce keyword imples (to me anyway)
that it's going to take a binary operator and map it over a list so that
it reduces it to a single value. The example looks like it's going to
produce a list of values. Is that right?
my @xs_and_ys = [1, 2, 3, 4, 5, 6, 7, 8];
does that give
$sum_of_powers = 3; # (0, 1, 2) (3, 4, 5) (6, 7, 8)
$sum_of_powers = 4; # (0, 1, 2) (1, 3, 4) (82, 5, 6) (15707, 7, 8)
or
$sum_of_powers = 5780508; (0, 1, 2) (1, 3, 4) (82, 5, 6) (15707, 7, 8)
I get the impression it's supposed to be that last one, but can't figure
out how it's supposed to work. Also was reduce defined anywhere i.e.
is it a built in or a subroutine?
cheers
Andrew