there is
hook =: 2 : '([: u v) : (u v) '
amend =: 2 : ' u hook (n { ]) n} ]'
a bit more flexible in that it uses an ambivalent verb.
^. amend 3 i._8
7 6 5 1.38629 3 2 1 0
2 ^. amend 3 i._8
7 6 5 2 3 2 1 0
in your examples, &. applies a monadic verb to each dyadic parameter, so it
"nearly worked " in your last example.
(3&{) b. _1
0 1 2 3&{
I'm unsure how that could ever work with &. as the inverse is applied to the
result of '3&{'. I guess if it was a record of 4 or more items.
+:&.(3&{) i. 5 8
48 50 52 54
+:&.(2&{) i. 5 8
32 34 36
----- Original Message -----
From: David Lambert <[email protected]>
To: programming <[email protected]>
Cc:
Sent: Thursday, March 26, 2015 12:37 AM
Subject: [Jprogramming] Under From
The UnderFrom adverb evaluates verb u on x{y and replaces x{y with the
result. (In c, array notation y[x] = u(y[x]) What problems ensue from
implementing an obverse to from?
UnderFrom =: (@:{)(`[)(`])}
3 ^.UnderFrom i._8 NB. ln of the fourth item
7 6 5 1.38629 3 2 1 0
NB. under from
3 ^.&.{ i._8
|domain error
| 3 ^.&.{i._8
^.&.(3&{) i._8
|index error
| ^.&.(3&{)i._8
I hope this is a better idea than the marginally useful global `for'
assignment which I would occasionally use to debug. for_i: do. end.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm