develooper Front page | perl.perl6.language | Postings from April 2005

Hyper-slices?

Thread Next
From:
David Christensen
Date:
April 17, 2005 07:51
Subject:
Hyper-slices?
Message ID:
3ba27c36b384d8427b01ce1fe89cfe24@dwci.net
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

my @transposed = @matrix>>[0..2];

I don't know if this case has been discussed earlier; is extracting an 
element considered a unary operation?  Is there some use for this 
notation, other than what  I just said?

I suppose the same could be said for Lists of Hashes:

my @records=({name=>"Tom",age=>27},{name=>"Dick",age=>33});

my @names= @records>>{'name'};
say @names;
# Tom Dick

Of course, for this to be useful, the lists would have to be 
homogenous; @array is List of Hashes (excuse the syntax; I'm still 
getting up to speed with a lot of the P6 specific issues).

Again, apologies if this is a closed domain/already has some other 
method of retrieving the same information.

Thanks,

David Christensen


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About