Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Vs=: 4r3p1"_ * ] ^ 3:

What's the "_ for?





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.

Right, thank you!

I recognised the " as rank but got confused by the _ reading https://code.jsoftware.com/wiki/Vocabulary/under, it seemed to be 'rank negative' and didn't see what that did.

> second nature once you internalize J, but so so foreign until you do.

Indeed!




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: