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

Re: zip with ()

Thread Previous | Thread Next
August 1, 2005 04:37
Re: zip with ()
Message ID:

Ingo Blechschmidt wrote:
> 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

Why flattened? Shouldn't that be *(@odd, @even)?

>                             # 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?

>                             # tries to zip this one list, resulting in 
>                             # 13572468.

If the list of two array refs is not flattened, the result should be
12345678 because how should &zip distinguish it from the other cases?

The crux of the first case not requiring parens is that &zip is declared
as listop and as such consumes the @even after the , which otherwise would
be left for &say. And if &say weren't declared/assumed listop, the @even
would be evaluated in Void context and not appear in the print at all.

Or do I miss something important? E.g. has () become a circumfix deref op?
$TSa.greeting := "HaloO"; # mind the echo!

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