[Jprogramming] Index replacement

Brian Schott schott.brian at gmail.com
Sun Nov 26 02:27:55 HKT 2006


Dan,

	Ok, you got me: what in the world is k? I understand
the `:6 puts together the verb train to its left. I am
assuming that k produced most of the lefthand verb in the
gerund form of amend in l. But I am unclear about several
other things, including

a)  is the verb train in k a fork or a hook (if it's
a fork I guess it picks up its third tine from l )?

b)  in the definition of k, I understand that ties (`'s)
are needed to separate the verbs, but why is one tie on the
left and one on the right of its verb? And if there is a
third verb to make a fork, why does it not neet a tie?

c) to what is (&[)("_1)  in k attaching itself or waiting
for or whatever? I guess the answer is the rest of l except
the amend, but I cannot see how.

Thank you,

On Fri, 24 Nov 2006, Dan Bron wrote:

+ JC,
+
+ Short answer:
+
+ 	   k   =:  (&[) ("_1) (#/.~@:]`) (`({~ ~.)) (`:6) ~
+ 	   l   =:  k (`(~.@:[)) (`]) }
+
+ 	   f   =:  ^&2
+ 	   v   =:  i.10
+ 	   ind =:  3 5 3
+
+ 	   ind f l v
+ 	0 1 2 81 4 25 6 7 8 9
+
+
+ A couple of points.  You say the result should be  r=:1 2 81 4 25 6 7 8 9  but:
+
+ 	(A)  (#r) is  9  whereas  (#v)  is 10 , so I'm assuming you forgot
+ 	     the first element,  0  .
+
+ 	(B)  You say  f  is  2^y  but  2^5  is  32  ,  not 25  , so I assume
+ 	     you meant y^2  (y-squared).  To that end, you might want to
+ 	     say  f=:  *:  rather  than  f=:  ^&2  .
+
+ Since you asked for "elegant", I decided to provide a tacit solution, to prove that such can done in the language.  If I were
+ writing this with intent of making it production code, I would probably make it explicit.  Explicit code, while not as beautiful
+ or cool, tends to be easier to read and maintain, and in complicated examples like this, usually faster.  For example, the tacit
+ code takes  ~.x  twice, which, in explicit code, could be calculated once and stored in a local name.
+
+ -Dan
+
+ ----------------------------------------------------------------------
+ For information about J forums see http://www.jsoftware.com/forums.htm
+

(B=) <----------my "sig"

Brian Schott
Atlanta, GA, USA
schott DOT bee are eye eh en AT gee em ae eye el DOT com
http://schott.selfip.net/~brian/


More information about the Programming mailing list