J arrays must be rectangualar, which means have the same number of cells
along each dimension. The 2nd row of a table can't be shorter than the 5th
row. The 18th plane in a cube (hyperrectangle) can't have fewer rows than
the 107th plane in that same cube.  Recursively: an array is a
1-dimensional list of items, all of which themselves have the same number
of items (the 1D list's items share the same length).

Therefore, your question boils down to this:

           mat=:i.2 3
           r90=:|."1@:|:"2
           
           ] zero =. r90^:0 mat
        0 1 2
        3 4 5
           ] one =. r90^:1 mat
        3 0
        4 1
        5 2
           ] two =. r90^:2 mat
        5 4 3
        2 1 0
           
           zero,one,two 
        0 1 2
        3 4 5
        3 0 0
        4 1 0
        5 2 0
        5 4 3
        2 1 0
           

So it isn't power (^:) that is adding the extra rows, it is append (,),
which is used to catenate the arrays produced by each successive
application of r90 (zero, one, and two). Append ensures that the resulting
array conforms to J's rules of data structures: in particular, it makes
sure all items have the same length (recursively). If one item is shorter
than its peers, J pads it (for numbers, it pads it with zeros; for
characters, spaces, etc).  

So that's what happened here. First J noticed that "one" had 3 items,
whereas "zero" and "two" had only two (each). So append extended (padded)
"zero" and "two" by adding an extra row of 0s, bringing their total length
to 3 rows (conforming to the length of "one").  Then J noticed that while
"one" had 3 rows, each of those rows was only 2 numbers long, whereas each
of the rows in "zero" and "two" had 3 numbers apiece. So append padded
each row of one with one extra number (a 0).

Make sense? In J, all arrays must be rectangular. You can't have "ragged"
arrays. If you try to combine arrays of different shapes, explicitly (e.g.
zero,one,two) or implicitly (e.g. r90^:(i.3) i. 2 3), J will pad the
arrays as needed to bring them to a common shape (so that they can become
the items of a rectangular array).

If you want to avoid the extra zeros, you must avoid catenating the arrays.
You can do this by putting each array in a box, then catenating the boxes.
The boxes wrap (hide) the underlying arrays, so all J sees is a nice,
smooth, rectangular array of boxes, and therefore doesn't see a need for
padding. The downside is the contents of boxes can't be addressed as
directly or readily as the items of an unboxed array, so there's a little
bookkeeping involved (and, like all forms of indirection or abstraction,
imposes some performance overhead). 

           (<zero),(<one),(<two)
        +-----+---+-----+
        |0 1 2|3 0|5 4 3|
        |3 4 5|4 1|2 1 0|
        |     |5 2|     |
        +-----+---+-----+
           r90&.>^:(i.3) <mat
        +-----+---+-----+
        |0 1 2|3 0|5 4 3|
        |3 4 5|4 1|2 1 0|
        |     |5 2|     |
        +-----+---+-----+
           
-Dan


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to