How to create a gerund from an array in J?

In J, we can use "_to create a constant function:

   k100 =. 100"_
   k200 =. 200"_

They can be used in gerund with other verbs:

   (+:`k100`k200`-:)`:0 [ 256
512 100 200 128

How to create a gerund directly from an array?

That is, I want to determine kthat it generates a gerund of constant verbs, for example:

   gk =: k 100 200     NB. (or '100 200 k' if it needs to be an adverb.)
   gk@.(0)''
100
   gk@.(1)''
200
+3
source share
2 answers

I agree with @eelvex that this smells like an XY problem . Using your example, can you provide us with a precedent for why you prefer to write

  gk =: k 100 200 300

  gk@.0'' 
100
  gk@.1''
200

instead

  GK =: 100 200 300
  0 { GK
100
  1 { GK
200

or even

  100*1+  0
100
  100*1+  1
200

etc.?

(@.) ({) , , , , , .

, - (, ) , , , . () - raison d'etre J-.

, , k.

   k=:[^:(__-:])L:_ 0" _1 0&({. __"_`'')

gerund ( ) , (__) , , . , __"_ __ . , 100 200 300 (100"_)`(200"_)`(300"_):

   gk=:k 100 200 300
   gk@.0 ''
100
   gk@.1 ''
200

, , , , , {&100 200 300 (100 * 1 + ]), gerund , , .

, .

+5

, - ( ". it):

 k =: [: ". [: ([,'`',])/('(' , '"_)' ,~ ":)"0
 gk =: k 100 200 300

 gk @. (2)''
 300

k (". f/g"0 y), f/g"0 y (num1"_) `(num2" _) `... y =: num1, num2, ....

.

+1

All Articles