Transpose an arbitrarily sized rectangular Matrix.




 
templates transpose
  def a: $;
  [1..$a(1)::length -> $a(1..last;$)] !
end transpose
 
templates printMatrix&{w:}
  templates formatN
    @: [];
    $ -> #
    '$@ -> $::length~..$w -> ' ';$@(last..1:-1)...;' !
    when <1..> do ..|@: $ mod 10; $ ~/ 10 -> #
  end formatN
  $... -> '|$(1) -> formatN;$(2..last)... -> ', $ -> formatN;';|
' !
end printMatrix
 
def m: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]];
'before:
' -> !OUT::write
$m -> printMatrix&{w:2} -> !OUT::write
 
def mT: $m -> transpose;
'
transposed:
' -> !OUT::write
$mT -> printMatrix&{w:2} -> !OUT::write
 