Conditional structures/J: Difference between revisions

Line 90:
(Y * -. B) + F&.(B&#) Y
4 3 25 7 121</lang>
 
Here <code>#</code> is J's "compress" or "selection" verb. For example <code>1 0 1 # 1 2 3</code> gives us <code>1 3</code>. And when we combine a verb and a noun, <code>&</code> curries the verb with that noun (so <code>+&1</code> produces a verb that adds 1 to its argument). And the two character token <code>&.</code> uses the verb on its right to map into a different domain and then its inverse to map back to the original domain. In other words, here we preprocess by eliminating the arguments from Y which we do not want to have changed and we post process by expanding the result back to its original length (and since 0 is the fill value for numeric arrays, we get 0s in the positions where we were ignoring elements of Y).
6,951

edits