> From: Viktor Cerovski > It is a bit more complicated: > > foldl1 =: / > foldr1 =: ~/(@:|.) > > as in: > > - foldl1 1 2 3 4 NB. (1-(2-(3-4))) > _2 > > - foldr1 1 2 3 4 NB. (((1-2)-3)-4) > _8 > > but I (still) don't think there is an easy way to define foldl and > foldr in > J.
I had come up with similar adverbs for foldl1 and foldr1 and was trying to define adverbs that took the initial value as a left argument to define foldl and foldr. Can anyone help me understand why these don't work? ]lst=: >: i. 5 1 2 3 4 5 foldl=: 1 : 'u/ x,y' 0 - foldl lst |domain error | 0 -foldl lst foldr=: 1 : 'u~/@:|. x,y' 0 - foldr lst |domain error | 0 -foldr lst ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
