Arrays in J-programming Language

How to make massive calls in the J programming language? For example, using C ++ as a pseudo-code language:

int M [100];  // declare an array called M
int j = 5;  //index into the array
int y = 10;  //value to store or load from the array

M[j] = y;  // store y into the array

y = M[j];  // load y from the array

What would these types of array access look like in idiomatic J?

+5
source share
1 answer

The literal (but still rather idiomatic) way to write this in J would be as follows.

m =: 100 $ 0   NB. This means create a 1d array consisting of 100 zeros.
j =: 5
y =: 10

With this initialization aside, we are now ready for the meat of the answer, which consists of two different ways of using the adverb }("Paragraph" Change "and" Change ") .

m =: y j } m

} J j - m y. : m, y j } m , , , } .

y =: j } m

} J j - m . y .

+7

All Articles