Like Pascal Jasmin pointed out, fold is overkill for this example. For example:
(1 vec} A)-:vec fold A 1 But this does suggest a way of illustrating the use of a fold conjunction, if that's what you want to focus on: (A ]F..{{1 (<x)} y}} vec) -: vec fold A 1 (Folds are "popular" right now, which is kind of interesting. But using them isn't really a substitute for understanding math nor for understanding the operations we use with folds.) Anyways... I hope this helps, -- Raul On Sat, Apr 23, 2022 at 2:02 PM Pawel Jakubas <jakubas.pa...@gmail.com> wrote: > > Dear J enthusiast, > > I try to play with fold functionality F... > and here solve more general cases, so when the accumulator structure is > different from the list structure that is iterated. > > To be concrete let's say we have the array, A, and a list of 2-elem > vectors, vec, > which institute coordinates (x,y) which I want to update in A. > ``` > A=: 10 10 $ 0 > ]vec=: 3 2 $ 1 2 3 4 5 6 > 1 2 > 3 4 > 5 6 > ``` > Now, I can of course solve this recursively, eg: > ``` > fold=: 4 : 0 > 'r c' =. ,"0 $ x > if. (r=1) do. > 'x0 y0'=. {. x > 1 (<(x0),(y0)) } y > else. > 'x0 y0'=. {. x > y1=.1 (<(x0),(y0)) } y > (}. x) fold y1 > end. > ) > vec fold A > 0 0 0 0 0 0 0 0 0 0 > 0 0 1 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 > 0 0 0 0 1 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 1 0 0 0 > 0 0 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 > ``` > > How to start with A, use vec as iterator list in one of folds F.. and end > up with updated A as above? > Thanks in advance! > Cheers, > Pawel Jakubas > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm