Matthew Brand asked:
> How do I specify the index for amend?
Amend treats all arrays the same, whether numeric, literal, symbolic, or
boxed. Thought about this way, amend can only "see" the top level of a
boxed array -- it cannot penetrate within a box. So, given an array of
boxes, you could easily address and amend a box or set of boxes, but you
can't address or amend their contents.
You could do what you want with:
(}: , 99 (1})&.>&.> {:) (<i.10);<(<i.3)
+---------------------+--------+
|+-------------------+|+------+|
||0 1 2 3 4 5 6 7 8 9|||0 99 2||
|+-------------------+|+------+|
+---------------------+--------+
But you'd have to craft a custom solution for each new problem. We could
address this.
Now, { is like } in that it is unbiased: it treats all arrays the same,
and doesn't penetrate boxes. However, we also have {:: which allows one
to address the contents of boxes, and also tells you how to do that (for a
given boxed array it can produce a "map" of nested indices for addressing
any level of the boxed array).
For example:
] d=:(<i.10);<(<i.3)
+---------------------+-------+
|+-------------------+|+-----+|
||0 1 2 3 4 5 6 7 8 9|||0 1 2||
|+-------------------+|+-----+|
+---------------------+-------+
{:: d NB. Map d (monad)
+------+------+
|+----+|+----+|
||+-++|||+-++||
|||0||||||1||||
||+-++|||+-++||
|+----+|+----+|
+------+------+
(1;'';1) {:: d NB. Using map, address interesting parts of d (dyad)
1
So now we know how we would (in theory) address the part of d we'd want
to change. However, while we can select nested data using {:: , what we
lack is a way to amend nested data. That is, we have { and its partner
} but we only have {:: -- its partner does not exist [1].
But there have been various models of }:: posted to the Forums over the
years. You might want to see if you can adapt something from this thread
to your needs:
http://www.jsoftware.com/pipermail/general/2001-January/005175.html
but most of the code will need updating to the current version of J.
-Dan
[1] Actually, interesting J trivia: }:: *does* exist, in that J accepts
it without a spelling error (as opposed to eg }::: ), but it is
currently undefined (that is, fully parameterized, it always produces a
nonce error).
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm