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

Re: zip with ()

Thread Previous | Thread Next
Luke Palmer
August 1, 2005 09:45
Re: zip with ()
Message ID:
On 8/1/05, Ingo Blechschmidt <> 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

    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?


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