I don't know whether the following is what you mean by "intrinsic rank".
Certain (quite a few) primitives are implemented by code that "know" what
their ranks are supposed to be and know that they are currently invoked via
the rank operator with particular ranks. For example, if you say 2{."1 x
the C function that implements "take" is given the 2 and the x *in toto *and
"know" that it's being called with rank 1*. *You can see the effect of
this by doing a benchmark:
take=: {.
x=: 50 1e5 ?@$ 0
ts '2 {."1 x'
1.4527e_5 1920
ts '2 take"1 x'
0.0209496 1.05082e6
This is called "Integrated Rank Support" in
http://www.jsoftware.com/papers/rank.htm .
On Wed, Jun 13, 2012 at 8:08 AM, Raul Miller <[email protected]> wrote:
> If I understand the interpreter properly, it has a mechanism called
> intrinsic rank, where the body of a verb is allowed to act at a higher
> rank than what has been declared for the verb itself.
>
> In other words, something like this:
>
> IntrinsicRank=:2 :0
> Z=. 0"n y
> (Z ]"(-#$Z) u) y
> :
> Z=. x 0"n y
> x (Z ]"(-#$Z) u) y
> )
>
> And, if V is a verb created by IntrinsicRank V b. 0 would return n
> (which is why this would have to be implemented in the interpreter --
> the above model is not sufficient).
>
> This could either be a primitive (perhaps b:) or a foreign (perhaps
> Ir=: 128!:6).
>
> It seems to me that this could be a useful mechanism for J programmers.
>
> First, with this mechanism you could recursively or inductively build
> an array result and amortize the costs of this process over the entire
> result rather than having to memoize or recompute intermediate results
> for each cell.
>
> For example:
>
> fibonacci=:3 :0 b: 0
> y{(,+/@{.~&_2)^:(>./,y) 0 1
> )
>
> Second, with this mechanism you could investigate (debug) mechanisms
> which derive verbs which are sensitive to the rank of the component
> verbs.
>
> For example:
>
> (i.2 3) +/ .(*&([smoutput)b:0) i.3 2
>
> (And note that the above become legally valid statements if you
> replace b: with " -- and the results of these example would be
> identical. But the time taken by fibonacci will be significantly
> higher and the session manager display from the smoutput example will
> be different.)
>
> Thoughs?
>
> Thanks,
>
> --
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm