Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: for @list ⊂

3 views
Skip to first unread message

Luke Palmer

unread,
Mar 12, 2005, 8:56:17 PM3/12/05
to Rod Adams, Perl6 Language List
Rod Adams writes:
> Are the following all legal and equivalent?
>
> for 1..10 -> $a, $b { say $a, $b };
>
> for 1..10 { say $^a, $^b };
>
> sub foo ($a, $b) { say $a, $b };
> for 1..10 &foo;

Almost. The last one should be:

for 1..10, &foo;

> What happens with:
>
> for 1..10 -> *@a { say @a };

Good question. That's a function of how C<for> interprets the arity. The
formal arity of a sub with *@ is Inf, so I suppose say would get 1..10
and the loop would run once.

That's probably the best way for C<for> to behave, because that's what
I'd expect in this case.

Luke

Rod Adams

unread,
Mar 12, 2005, 8:48:27 PM3/12/05
to Perl6 Language List
Are the following all legal and equivalent?

for 1..10 -> $a, $b { say $a, $b };

for 1..10 { say $^a, $^b };

sub foo ($a, $b) { say $a, $b };
for 1..10 &foo;


What happens with:

for 1..10 -> *@a { say @a };

-- Rod Adams



Rod Adams

unread,
Mar 12, 2005, 9:23:34 PM3/12/05
to Perl6 Language List
Luke Palmer wrote:

>Rod Adams writes:
>
>
>>Are the following all legal and equivalent?
>>
>> for 1..10 -> $a, $b { say $a, $b };
>>
>> for 1..10 { say $^a, $^b };
>>
>> sub foo ($a, $b) { say $a, $b };
>> for 1..10 &foo;
>>
>>
>
>Almost. The last one should be:
>
> for 1..10, &foo;
>
>

Doh! I knew that.

>
>
>
>>What happens with:
>>
>> for 1..10 -> *@a { say @a };
>>
>>
>
>Good question. That's a function of how C<for> interprets the arity. The
>formal arity of a sub with *@ is Inf, so I suppose say would get 1..10
>and the loop would run once.
>
>That's probably the best way for C<for> to behave, because that's what
>I'd expect in this case.
>
>

That's what I'd expect as well. It's not terribly useful, but worth
clarifying.


A folowup question is how to get:

for @a, @b, @c -> @x { say @x };

to work properly. "Properly" being defined here as three iterations.

The best guess I can put forward is:

for \@a, \@b, \@c -> @x { say @x };

certainly

for \@a, \@b, \@c -> $x { say $x };

should work. Are there any non-slashy versions of this?

-- Rod Adams

Miroslav Silovic

unread,
Mar 14, 2005, 7:16:57 AM3/14/05
to r...@rodadams.net, perl6-l...@perl.org
r...@rodadams.net wrote:

> for \@a, \@b, \@c -> $x { say $x };
>
> should work. Are there any non-slashy versions of this?

I'd guess

for @a; @b; @c -> $x { say $x;}

or

for (@a; @b; @c) -> $x { say $x;}

(are parens mandatory here?)

Miro

0 new messages