On Sun, Mar 30, 2008 at 08:21:39AM -0700, Mark A. Biggar wrote: > The reduce meta-operator over - in APL gives alternating sum, similarly > alternating quotient for /, which only works if you right associate > things. > > [-] 1,2,3,4,5,6 => 1-2+3-4+5-6 # pseudo-apl > > [/] 1,2,3,4,5,6 => (1*3*5)/(2*4*6) #pseudo-apl > > note that would break the perl 6 simple rule that [-] 1,2,3 => 1-2-3, > but gives something much more useful. There currently is no easy way to > do alternating sum/quotient in perl6.
How about...? # alternating sum of elements in @list $altsum = [+] ({ $^a - $^b } for @list); Pm