At 12:00 AM 9/12/00 +1100, Jeremy Howard wrote:
>[EMAIL PROTECTED] wrote:
> > Reading through the examples left me wondering about some
> > technicalities:
> >
> > > @t[|i;|j] = @a[|j;|i]; # transpose 2-d @a
> >
> > Written like this it would require that @a is exact 2-dim, i.e. it would
> > not just swap the first two dims of any n-dim array? I suppose if I'd
> > want that I'd write
> >
> > @t[|i;|j;] = @a[|j;|i;]; # trailing ';' implies there might be
> > trailing dims
> >
>Not necessary. Since arrays support all the syntax of a plain old list of
>lists, and the |i syntax just creates an implicit loop, the example quoted
>from the RFC will work with other sized arrays. In fact, if it was only 2d,
>it would more properly be:
>
> $t[|i;|j] = $a[|j;|i]; # transpose 2-d @a
I think it's fair to say that I goofed, and was probably inconsistent with
my use of @ and $ in RFC207. It was the hardest (conceptually) of the RFCs
I wrote, and it was written late at night -- my thinking probably wasn't as
clear as it could have been. I know I delayed in writing it because it
posed interesting challenges to syntax and semantics.
I think what I was thinking was that |i would act as a list, therefore
@t[|i] is syntactically an array slice, and therefore uses @, not $. I'm
not so certain that that makes a tremendous amount of sense.
The problem is that the isolated expression ~a[|i;|j] (using ~ as a
placeholder for $ or @) evaluates to a 2D array, so should use @, but the
|i;|j syntax is used to refer to a single element, so it's sort of a
scaler, and should use $.
While something like "$t[|i;|j] = $a[|j;|i]
>With three dimensions, each implicit loop in
>
> @t[|i;|j] = @a[|j;|i]; # transpose 2-d @a
>
>is assigning the _list_ (or 1d array) at @a[|j;|i] to the appropriate index
>in @t. Ditto for >3 dimensions, except that it is a >1d array (or LOL) that
>is being assigned at each index through the implicit loop.