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

Re: zip with ()

Thread Previous | Thread Next
From:
Ingo Blechschmidt
Date:
August 1, 2005 03:23
Subject:
Re: zip with ()
Message ID:
dckt73$qb9$1@sea.gmane.org
Hi,

Andrew Shitov wrote:
> I tried zip under pugs.
> 
>     my @odd = (1, 3, 5, 7);
>     my @even = (2, 4, 6, 8);
>     my @bothA = zip @odd, @even;
>     print @bothA;
> 
> This code prints 12345678 as expected.
> 
> After parenthesis were used to group zip arguments, results changes
> to 13572468. Is it right?

Whitespace is significant:

    say zip @odd, @even;    # &zip gets two arguments, result is
                            # 12345678.
    say zip(@odd, @even);   # &zip gets two arguments, result is
                            # 12345678.
    say zip (@odd, @even);  # &zip gets only one argument, the flattened
                            # list (@odd, @even), containing the
                            # elements (1,3,5,7,2,4,6,8). Then &zip
                            # tries to zip this one list, resulting in 
                            # 13572468.


--Ingo

-- 
Linux, the choice of a GNU | To understand recursion, you must first
generation on a dual AMD   | understand recursion.  
Athlon!                    | 


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