Re: RFC 272 (v1) Arrays: transpose()
[email protected] ("Jeremy Howard") Sat, 23 Sep 2000 23:03:41 +1100
| Newsgroups | perl.perl6.language.data |
|---|---|
| Message-ID | <000501c02556$54397240$0100a8c0@jeremy> |
[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?