David Christensen writes: > Quick thought --- > > Does the current design of Perl 6's hyper operators allow for > "hyper-slices"? I.e., if I want to model a matrix by using a list of > lists, is the following code valid/useful? > > my @matrix=([1,2,3],[4,5,6],[7,8,9]); > > my @row = @matrix[0]; # first row > my @col = @matrix>>[0]; #first column
Almost. my @col = @matrixÂ.[0] > my @transposed = @matrix>>[0..2]; The thing that makes me wonder about that is whether it builds anonymous arrays inside for you, or whether it just flattens everything out. Obviously in this case it *should* give you arrays. On the other hand, if you did the standard map transform that hypers do: my @transposed = map { $_[0..2] } @matrix Then it's clearly flattening. What I'm currently thinking is that Perl is terrible for matrix stuff. Maybe we should keep it that way, and punt to PDL. But as it stands, we have no hope of appeasing the mathematicians in this area without really redoing hyper stuff. And I think that the hyper stuff is pretty close to right for non-matrix purposes, so it would be hard to redo it without perturbing what we have. Luke