[EMAIL PROTECTED] writes:
: More questions on downwards binding,
: 
: > for @foo -> $a, $b {  # two at a time
: >     ...
: > }
: 
: Interpretation #1:
:     for @foo[0..$foo:2] -> $a,
:         @foo[1..$foo:2] -> $b
:     { ... }
: 
: Interpretation #2:
:     for @foo -> $a { $b := $a; ... }
: 
: I like this second one, as a short-cut, but it's not worth it. Am I
: correct in assuming (as I henceforth shall) that ->(list) is a
: distributive binding operation, which spreads all the lhs list elements
: into rhs list elements?

Neither of these is an accurate view of the current design.  The

    -> LIST { ... }

construct is declaring a closure with a certain parameter signature.
The construct interpreting that closure (C<for> in this case) is free
to pass arguments to those parameters however it sees fit.

: ==========
: 
: Is it legitimate to make the precedence of -> high, and then
: just require that distributive binding use parens? (Which resonates
: well with existing usages: my ($arg1, $arg2) = @_;)
: 
: for @ary1 -> ($nam1, $pw1, $uid1, $gid1, $gcs1, $dir1, $shl1 ),
:     @ary2 -> ($nam2, $pw2, $uid2, $gid2, $gcs2, $dir2, $shl2)
: {
:    ...
: }

Yes, we could do it that way.

: ==========
: 
: > : What would the default-variable scheme do in this context? 
: > 
: > That's a problem.  But a more basic problem is, what would a C<when>
: > do?
: 
: Given that comma is a list operator, C<when> takes the last one.

No, that's Perl 5 thinking.  In Perl 6 the comma always produces a list
even in scalar context.

: for @a1 -> $a1,
:     @a2 -> $a2
: {
:     when /Larry Wall/i { ++larrymeter; }; # Uses $a2 implicitly.
:     when $a1 =~ /Perl/ { ... };           # doesn't.
: }

It would be more likely to assume a given of any($a1,$a2).

: ==========
: > you might not be able to say
: >      mumble $a -> $b,
: >           $b -> $a
: >      { ... }
: > to mean
: >      mumble $a, $b -> $b, $a
: >      { ... }
: 
: mumble ($a, $b) -> ($b, $a) # Makes a list and distributively binds it.
: { ... }
: 
: ===========
: > And I think we have to allow for the case that there are no actuals
: > to bind to the formals yet, which means we need an ordinarly looking
: > parameter list after the ->.  That is, as it currently stands, you
: > can say
: >     my $closure = -> $a, $b { ... }
: > as an equivalent to
: >     my $closure = sub ($a, $b) { ... }
: > 
: > (The only difference being that the latter pays attention to "return"
: > exceptions because it has an explicit "sub".)
: 
: How would you invoke such a defun?

Like any other anonymous subroutine or closure.

: $closure($a, $b)

That would work.

: for @list $closure
: map $closure @list
: grep $closure @list

Probably not.

: Finally, what does <- do? 

Numeric comparison of a negated value.  Unless we turn := into <-, which
would probably drive the mathematicians nuts.

Larry

Reply via email to