Verbal amend is under-documented and rarely used, due to the property you've
discovered.
In fact, verbal amend is only ever used when that property is desired.
Otherwise, one would use the noun or gerundial form.
The property is that in x f} y the verb f addresses indices into the
__ravel__ of y. So, for example, x 4:} y inserts x at 4 { (,y) .
This has been a known bug for a long time:
http://www.jsoftware.com/jwiki/System/Interpreter/Bugs#specificationofverbal
amendincomplete
-Dan
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Simon Clarkstone
Sent: Friday, July 15, 2011 9:15 AM
To: [email protected]
Subject: [Jprogramming] Puzzling behaviour of u} (verb-ammend)
(Re-sending after adjusting expected from-address.)
I am being confused by the amend adverb's behaviour when applied to a verb.
http://www.jsoftware.com/help/dictionary/d530v.htm
I thought that the output of the verb just supplied some indices, and
} then behaved as if applied to that noun, but that seems not to be
the case (in j701):
a =: 'abc';:'def'
'*' (4:}) a
abc
d*f
This looked odd. I experimented further.
I know that '4:' will always return a single 4 (rank 0), but upon
substituting that result, I find:
'*' (4}) a
|index error
| '*' (4})a
This makes sense, as 4 tries to address the row 4 of the table (and
only rows 0 and 1 exist)
The behaviour of u} is as if the array is being ravelled, modified
using the noun indices, and unravelled. The behaviour matches:
($a)$ '*' (4}) ,a
abc
d*f
Am I misunderstanding the intended nature of u}? The definition in
the documentation does not mention this pseudo-ravelling, though the
first example illustrates it. How do I avoid it happening? Is it a
known bug kept for compatibility; I could find no mention in the
archives?
Related: is there a conventional way to convert between ravelled and
non-ravelled indexes, for a given array shape? I would rather not do
it in 20 characters if I could do it in 5.
--
src/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm