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

Re: zip with ()

Thread Previous | Thread Next
From:
Ingo Blechschmidt
Date:
August 1, 2005 05:55
Subject:
Re: zip with ()
Message ID:
loom.20050801T144614-912@post.gmane.org
Hi,

TSa (Thomas SandlaƟ <Thomas.Sandlass <at> orthogon.com> writes:
> Ingo Blechschmidt wrote:
> >     say zip (@odd, @even);  # &zip gets only one argument, the flattened
> >                             # list ( @odd, @even), containing the
> 
> Why flattened? Shouldn't that be *(@odd, @even)?

IIUC:
    say zip *(@odd, @even);
    # &zip gets called with the parameters 1, 3, 5, 7, 2, 4, 6, 8.

    say zip (@odd, @even);
    # &zip gets called with one argument, (1, 3, 5, 7, 2, 4, 6, 8).

    say zip (\@odd, \@even);
    # &zip gets called with one argument, ([1, 3, 5, 7], [2, 4, 6, 8]).

In general, (@foo, @bar) returns a new list with the element joined,
i.e. "@foo.concat(@bar)". If you want to create a list with two sublists,
you've to use (\@foo, \@bar) or ([@foo], [@bar]). But of course, I could
be totally wrong. :)

> >                             # elements (1,3,5,7,2,4,6,8). Then &zip
> 
> Why not ([1,3,5,7],[2,4,6,8]) list of two array refs?

Because you'd have to explicitly take reference to them:
    say zip (\@ood, \@even).

(Can somebody confirm my thoughts?)


--Ingo


Thread Previous | 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