← Back to context

Comment by gcanyon

4 months ago

Vague recollection, could be wrong -- in J, you can apply a "rank" to verbs, which determines how the verb applies to its arguments. So for example, if we define that average verb:

avg =: +/%#

then we can say

avg 2 4

and get 3

We can also say:

x =: i.2 3 4

and that makes an array like so:

   0  1  2  3
   4  5  6  7
   8  9 10 11

   12 13 14 15
   16 17 18 19
   20 21 22 23

And then we can do things like:

      avg"1 x
   1.5  5.5  9.5
   13.5 17.5 21.5
      avg"2 y
   4  5  6  7
   16 17 18 19
      avg"3 y
   6  7  8  9
   10 11 12 13
   14 15 16 17

In this instance I believe the "_ is just giving back 4r3p1 = 4.18879 for each of the arguments handed to the rest of the verb. This is one of those things that is second nature once you internalize J, but so so foreign until you do.