June Kim wrote:
> Is there a way to make a tacit definition of the verb for arbitrary rank
> arrays?
This question has been raised before, and I have a nascent Essay on the Wiki
about it. If I ever finish it, it will demonstrate a suite of methods for
operating on all axes. My current favorite (first shown to me by Kirk Iverson
when he was teaching me J) is the idiom 0&|:@:f^:(#@:$) For example,
f=:0 , ,&0
]A=: 0&|:@:f^:(#@:$) i.2 2 2
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 1 0
0 2 3 0
0 0 0 0
0 0 0 0
0 4 5 0
0 6 7 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
A -: (0,~0,])"3 (0,~0,])"2 (0,~0,])"1 i.2 2 2
1
The approach is purely tacit, as you desire. In fact, it can be written as a
purely tacit adverb:
oaa=:(0&|:@:) (^:(#@:$)) NB. on all axes
A-: (0 , ,&0) oaa i. 2 2 2
1
Your approach f"n f"(n-1) .... f"0 y is interesting and I will think about
ways of tacitizing it. I already tried a couple of obvious routes, but the one
that worked was cheating (used 128!:2 ) and the one that wasn't [as
obviously] cheating didn't work.
> I think "apply to all axis" is sometimes useful in some cases such as:
> reversing on all axis:
The most fun way to do this is:
];.0 y
Which is just how the monad ;.0 is defined. Roger posted it as a solution
in a related thread:
http://www.jsoftware.com/pipermail/programming/2005-December/000304.html
another thread that applies to operating on all axes was "shave" (the
inspiration for and macguffin of my pending Essay):
http://www.jsoftware.com/pipermail/programming/2007-October/008302.html
Hope this helps. I'll let you know if I make any headway in tacitizing f"n
.... f"0 (*).
-Dan
(*): If the following proposal had been adopted, this problem would be trivial:
http://www.jsoftware.com/jwiki/System/Interpreter/Requests06#head-6d80783f357671339d77503eaea000fe3e9b5f5f
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm