This and other RFCs are available on the web at
  http://dev.perl.org/rfc/

=head1 TITLE

Arrays: transpose()

=head1 VERSION

  Maintainer: Jeremy Howard <[EMAIL PROTECTED]>
  Date: 22 Sep 2000
  Mailing List: [EMAIL PROTECTED]
  Number: 272
  Version: 1
  Status: Developing

=head1 ABSTRACT

It is proposed that a new function C<transpose> be added to Perl.
C<transpose($dim1, $dim2, @list)> would return @list with $dim1 and $dim2
switched. It would return an alias into the original list, not a copy of
the elements.

=head1 DESCRIPTION

It is proposed that Perl implement a function called C<transpose> that
transposes two dimensions of an array, and is evaluated lazily. L<RFC 202>
gives an overview of the proposed multidimensional arrays that
C<transpose> works with. For instance:

  @a = ([1,2],[3,4],[5,6]);
  @transposed_list = transpose(0,1,@a);   # ([1,3,5],[2,4,6])

This is different to C<reshape> (see L<RFC 148>) which does not reorder
its elements:

  @a = ([1,2],[3,4],[5,6]);
  @reshaped_list = reshape([3,2],@a);   # ([1,2,3],[4,5,6])

C<transpose> is its own inverse:

  @transposed_list = transpose(0,1,@a);   # ([1,3,5],[2,4,6])
  @orig_list = transpose(0,1,@transposed_list); # (([1,2],[3,4],[5,6])
  @a == @orig_list;   # true

If C<transpose> refers to a dimension that does not exist, empty
dimensions autovivify as necessary:

  @row_vector = (1,2,3,4);
  @col_vector = transpose(0,1,@row_vector);   # ([1],[2],[3],[4])

C<transpose> does not make a copy of the elements of its arguments; it
simply create an alias:

  @row_vector = (1,2,3,4);
  @col_vector = transpose(0,1,@row_vector);  # ([1],[2],[3],[4])
  $col_vector[[0,1]] = 0;
  @row_vector == (1,0,3,4);                  # True
    
=head1 IMPLEMENTATION

RFC 90 discusses possible approaches to implementing aliasing.

=head1 REFERENCES

RFC 90: Arrays: merge() and unmerge()

RFC 148: Arrays: Add reshape() for multi-dimensional array reshaping

Reply via email to