On Tue, Jan 25, 2022 at 12:13 AM Elijah Stone <[email protected]> wrote:
> Case in point: I made a quadratic bezier curve renderer recently,
> representing the curve data using a three-dimensional array. So I
> had to choose how to order the axes. I got it wrong the first
> time, and had to restructure some code as a result. It might not
> have mattered so much, had there been a primitive to put the axes
> directly in the right order at the point where that was needed.
Isn't dyadic transpose exactly that mechanism? It lets you "index
the axes":
$i.p:i.8
2 3 5 7 11 13 17 19
$1 3 5 7 0 2 4 6 |: i.p:i.8
3 7 13 19 2 5 11 17
Also, though, if you have an operation F defined on matrices (where
F preserves the leading dimension of its argument in its result)
and you need it to work on an array of arbitrary dimension N (which
is probably larger than 2), you can define an adverb RN which will
extend F RN would work that way (as long as the appropriate dimension
is last):
RN=: {{ (}.~ _2 >. 1+-@#)@$ $ [:u (,@}: , {:)@$ $ , }}
That said, a big problem we face is "generalizing from one example".
(Or, more generally: overgeneralization...) It's easy to do, and
one example is certainly better than no examples (which is why use
cases are so nice for software development). But language changes
should be rare (because of the learning costs it imposes on the
people who know the language, and because of the documentation cost
it imposes, and of course because of the implementation and maintenance
efforts required by those changes).
Thanks,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm