[EMAIL PROTECTED] wrote:
> How about (if perl6 allows passing arrays implicitly by reference
> without arglist flattening)
>
>     transpose @arr, $a, $b;       # xchg
>     transpose @arr, {$a => $b};   # mv
>     transpose @arr, [0,3,4,1,2];  # PDL reorder
>
You know, I had just logged in to post almost the same suggestion! Only I
was going to suggest just:

    transpose $a, $b, @arr;       # xchg
    transpose [0,3,4,1,2], @arr;  # PDL reorder

(I'm not assuming the no-flattening thing, since that's another source of
angst altogether!)

So where is mv(), you ask? If you use the 'reorder' syntax, but don't
specify all of the dimensions in the list ref, then the remaining dimensions
are added in order:

  # Where @arr is a rank 5 array...
  transpose ([3], @arr) == transpose ([3,0,1,2,4], @arr);
  transpose ([0,3], @arr) == transpose ([0,3,1,2,4], @arr);

This doesn't give a shortcut like PDL's $arr->mv($a,$b) if $b>0, but
normally you would use $b = 0 anyway. For $b>0, you would have to specify
the whole list up to $b (like the 2nd example above).

BTW, I notice that you're using dimension numbering starting at 0 for your
transpose() examples. Is everyone happy to start at 0 rather than 1?


Reply via email to