You have to make it a dyadic verb See DoJ Explicit : foldl=: 1 : 0 : u/ x,y )
----- Original Message ----- From: "Sherlock, Ric" <[email protected]> To: "Chat forum" <[email protected]> Sent: Thursday, May 14, 2009 12:38 PM Subject: Re: [Jchat] Fold (Wikipedia) >> 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
