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

Re: zip with ()

Thread Previous | Thread Next
From:
Luke Palmer
Date:
August 1, 2005 09:45
Subject:
Re: zip with ()
Message ID:
7ca3f01605080109453f1dfb62@mail.gmail.com
On 8/1/05, Ingo Blechschmidt <iblech@web.de> wrote:
> 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. :)

I think that's right.  However, it might be a good idea not to
auto-enreference such bare lists:

    sub foo ($x) {...}
    foo (1,2,3,4,5);   # foo gets called with [1,2,3,4,5]

When you could just as easily have said:

    foo [1,2,3,4,5];

And we'll probably catch a lot of Perl 5 switchers that way.  That
actually makes a lot of sense to me.  The statement:

    my $x = (1,2,3,4,5);

Looks like an error more than anything else.  That's the "scalar
comma", which has been specified to return a list.  But maybe it
should be an error.  The main reason that we've kept a scalar comma is
for:

    loop (my $x = 0, my $y = 0; $x*$y <= 16; $x++, $y++)
    {...}

However, I think we can afford to hack around that.  Make the first
and last arguments to loop take lists and just throw them away.  Can
anyone think of any other common uses of the scalar comma?

Luke

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