The3DSquare
The3DSquare

Reputation: 13

Equivalent tacit expressions

I'm rather new to the J programming language and I have a question about equivalent tacit expressions in J.

I found two lines of J that were equivalent, but the conjunction in the code (^:)'s arguments were switched using the bracket operators.

I was mainly wondering how this expression:

u ^: x y

is equivalent to this expression:

x u @] ^: [ y

I would appreciate any J programmers to explain how the two are equivalent.

Upvotes: 1

Views: 151

Answers (1)

bob
bob

Reputation: 4302

I think that the way to look at this is to look at the tacit expression u@] ^: [ as a verb formed by the conjunction ^: between the two verbs u@] and [ . u@] is going to take the right argument y (to the exclusion of the left argument) and apply the monadic form of u to y. [ is going to use the left argument x as the value that will provide the number of repetitions of u as an operator of ^: .

For the explicit version, u ^: x y replaces the [ and ] verbs with their associated left and right arguments and since x is an operator of ^: , u ^: x is effectively a monadic verb with y as its argument.

Let's set

   a=. 3
   b=. 4
   vb =. +: NB. double
   vb ^: a b
32
   a vb @] ^: [ b
32
   a (vb @] ^: [) b NB. expression within parenthesis is clearly a verb
32

Upvotes: 1

Related Questions