Search code examples
jtacit-programming

J @ not working as expected


I'm just starting to try to pick up the J language, and am confused by the following:

   1 2 +/@{ i.4
1 2
   +/ 1 2 { i.4
3

when in the documentation for @ it says: "x u@v y ↔ u x v y"

I assume I'm just mistaking one part of speech for another, but can't figure it out

also, how do I tell what type of speech a name is?


Solution

  •    NB. u b. 0 returns the rank of u
       NB. the rank of a verb determines the arguments it applies to at a time
       NB. monadic + y applies to atoms; dyadic x + y applies to pairs of atoms
       + b. 0
    0 0 0
       NB. monadic +/ y and dyadic x +/ y apply to anything (unbounded rank)
       +/ b. 0
    _ _ _
       NB. monadic { y applies to arrays of atoms;
       NB. dyadic x { y applies to pairs of atoms and anything
       { b. 0
    1 0 _
       NB. u @ v has the rank of v
       +/@{ b. 0
    1 0 _
       NB. since 1 2 { i.4 returns atoms at a time, +/ works on atoms
       +/"0 [ 1 2 { i.4
    1 2
       NB. u @: v has unbounded rank
       +/@:{ b. 0
    _ _ _
       NB. +/ applies to all of 1 2 { i.4 at once
       +/"_ [ 1 2 { i.4
    3
    
       NB. mechanical translation to tacit form
       13 : '+/ x { y'
    [: +/ {