develooper Front page | perl.perl6.language | Postings from August 2006

Re: Pair of lists => list of pairs?

Thread Previous | Thread Next
Larry Wall
August 23, 2006 15:19
Re: Pair of lists => list of pairs?
Message ID:
On Thu, Aug 24, 2006 at 12:51:04AM +0300, Gaal Yahas wrote:
: On Wed, Aug 23, 2006 at 05:43:48PM -0400, Mark J. Reed wrote:
: > But is there an easy way in Perl6 to do it all in one go?  Should this work?
: > 
: > my %h = @k [=>] @v;
: You want a zip:
: my %h = @k ¥ @v;
: my %h = @k Y @v;     # ASCII fallback

That would have worked back when zip merely interleaved, but now it makes
sublists, and so we would have to teach hash assignment to transform [$k, $v]
into ($k,$v) or $k=>$v.  Might not be a bad idea.

: my %h = zip(@k, @v); # or maybe zip(@k; @v) this week?

It would be zip(@k;@v).  zip(@k,@v) would only have one dimension, so
would just concatenate the two lists and put each element into its
own sublist.

Alternately, for the old zip semantics we have each(@k;@v), which
makes a list with interleaved keys and values.  It's just there's no
operator like ¥ for it (yet).

But I'd still probably use a hyper-fatarrow for this case rather than
relying on interleaving.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About