Here's an explanation of the following: ins=:1 :0 : b=.1#~1 j.m e.~i.#y (x/:m) (I.-.b)} b expand y )
First off 1 :0 defines an adverb, and the part after the line that's just a : is the body of the dyad that that adjective produces. If that's not clear, and looking up "adverb" and "dyad" in J's dictionary doesn't help, feel free to ask questions... Within this body, we have three special names: m the noun which is the adjective's left argument once the adjective gets this noun, the combined result is a dyadic verb (dyad). x the noun which is the resulting dyad's left argument. y the noun which is the resulting dyad's right argument So, for _1 (2 3 ins) 2 3 5 7 m is 2 3 x is _1 y is 2 3 5 7 Thus, for b=.1#~1 j.m e.~i.#y b is 1 1 1 0 1 0 This is because i.#y is 0 1 2 3 m e.~i.#y is 0 0 1 1 1 j.m e.~i.#y is 1 1 1j1 1j1 1#~1 j.m e.~i.#y is 1 1 1 0 1 0 The trick here is that # can take a complex integer left argument -- the complex part tells how many zeros to insert after the corresponding element. (And, j. is a quick and easy way of building this complex argument.) So... once we have this, b expand y is 2 3 5 0 7 0 I.-.b is 3 5 Note that we could have used that complex number argument with # to get the same result as b expand y. And, note that we could have gotten 3 5 with (1+i.#m)+/:~m -- and there's other equally valid ways of getting here. And, x/:m sorts x using m as the sort key. In other words, I.-.b corresponds to sorted m, so we need x in the same order... Finally, we use merge (}) to merge these values from x into the corresponding places in the expanded y. I hope that makes sense? If not -- especially if after trying things out you can't reproduce my results (which might happen if I made a mistake and did not notice it), please ask. Thanks, -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
