J: Applying two arguments to a monadic verb produces strange results

StackOverflow https://stackoverflow.com/questions/18746073

  •  28-06-2022
  •  | 
  •  

문제

I was wondering what would happen if I apply two arguments to this verb: 3&*. If the left one is 1 all works as if it was only one argument:

   1 (3&*) 3
9
   1 (3&*) 4
12
   1 (3&*) 5
15

If I change it I discover why that worked:

   2 (3&*) 5
45
   3 (3&*) 5
135
   10 (3&*) 5
295245

It seems that the left argument is interpreted as a repetition like ^:. So the last one is equal to 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 5 (10 3's), or:

   5 * 3^10
295245

Can you explain this weird behavior? I was expecting something like domain error (which is ubiquitous), and that is thrown if I try to use fndisplay:

   require 'j/addons/general/misc/fndisplay.ijs'
   defverbs 'f'
   defnouns 'x y n'
   x (n&*) y
|domain error
|   x    (n&*)y
도움이 되었습니까?

해결책

it is documented.

x m&v y ↔ m&v^:x y

x u&n y ↔ u&n^:x y

&Bond from J dictionary

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top