Firstly, as Istvan wrote already, simply extracting the first element
with {. is a straight-forward way to "de-itemize" your data.
Taking that last description literally, you can (once again) let J figure
out how to de-itemize, given that itemize (monadic ,:) and inverse
are easily at hand:
Welcome to J! (ctrl+d to quit) 4.05+GDS changes/Feb 16 2008/19:19:49
inv =. ^: _1
,: inv i. 2 3 4
0 1 2 3
4 5 6 7
8 9 10 11
$ ,: inv i. 2 3 4
3 4
It is not really possible for me to derive what your are actually
trying to achieve, based on your code and your two single examples.
Your code looks a bit suspicious to me, though: beheading "output"
after taking an extra turn through the loop just looks irksome to
me. Also, I'd rather expect the initialization and loop to be more
along the typical pattern of
output =. i. 0 2 3
for. i. y do.
output =. output , ,: i. 2 3
end.
which caters for a rank-3 result in all cases. Usually such invariants
make it easier to build upon. Don't introduce special cases too early;
they will start pestering you on their own soon enough. Often enough,
you will have to "undo" the special case.
You may have noticed that I dropped the "_i" from the "for." Since
you are not referring to the loop index anyway, why mention it?
In the end, I would dispense with the entire loop and if you really
insist on the special casing, I'd use a simple if.:
example =. monad define
if. y=1 do.
i. 2 3
else.
y # ,: i. 2 3
end.
)
Or "(<:y)" -- again: it is not clear to me what you are trying to do.
Martin Neitzel
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm