YAP6 Operator: Reduce Operators - Part II

by Adriano Ferreira

Another article of the series "Yet Another Perl 6 Operator"


In a previous article , we introduced the reduction operators (like '[*]' and '[~]') which produced list operators from infix operators (like '*' and '~').



There is a variant of the reduction operator that operates over its list argument producing
all intermediate results along with the final result of the ordinary reduction.



[\\+] 1..5   # (1, 3, 6, 10, 15)


which is equivalent to



([+] 1), 
([+] 1, 2),
([+] 1, 2, 3),
([+] 1, 2, 3, 4),
([+] 1, 2, 3, 4, 5)

6 Comments

pjm
2007-12-28 16:29:54
Unfortunately there are a bunch of backslashes missing from the html-ified article. Looks like all but the "expanded" equivalent should have the backslash inside the opening square bracket of the reduction operator.



Adriano Ferreira
2007-12-29 03:21:04
It should be fixed now. And that's another fight I lose for O'Reilly MT. I haven't see no issue when previewing the article, but after you told it, I noticed that inside <pre> blocks, the backslashes needed to be repeated to appear.
rahed
2007-12-30 08:53:35
a previous article link is wrong
jhg
2008-01-03 18:23:28
Hmm.... semantically almost equivalent to the '/' (reduce) operator from APL (1968).


In APL, "+/a" applies "+ reduce" to vector "a" yielding a scalar result. Any infix operator could appear in front of the "/".


It's all the same stuff, rediscovered every couple of decades by a new generation of developers (viz. Virtualization, also from the '60s)

Andy Bach
2008-01-07 17:26:18
Previous article link is still broken, it should be:
http://www.oreillynet.com/onlamp/blog/2007/12/yap6_operator_reduce_operators.html
Adriano Ferreira
2008-01-08 04:28:10
@rahed @Andy Bach: fixed the "previous article" link. Thanks.