在 Sep 24, 2006 12:21 AM 時,Audrey Tang 寫到:


在 Sep 23, 2006 8:36 PM 時,Markus Laire 寫到:

On 9/23/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

     @args = [EMAIL PROTECTED],1,2,3;
-    push [,] @args;    # same as push @foo,1,2,3
+    push [,] @args;    # same as push(@foo: 1,2,3)

I don't quite understand this. Shouldn't C<[,] @args> be equivalent to
C<[EMAIL PROTECTED],1,2,3> just as C<[+] 0,1,2,3> is equivalent to C<0+1+2+3>?

So why is there C<:> instead of C<,> after C<@foo>?

Does this have something to do with the fact that C<@args> is
C<[EMAIL PROTECTED],1,2,3> and not C<@foo,1,2,3>?

Exactly. Per this interpretation, [EMAIL PROTECTED] is shorthand for \(@foo :), and [,] would first flatten the contents of @arg, and then process each one; if an element is Capture, it is joined into the current arglist; if it's not,
then it's made a simple positional.

I wasn't sure about this treatment, so I checked on #perl6 with Larry;
an alternative is to treat the elements of @foo always as positional
arguments, but that will make the two [,] calls below nonequivalent:

    my @args = [EMAIL PROTECTED], 1, 2, 3;
    [,] @args;
    [,] [EMAIL PROTECTED], 1, 2, 3;

I'd prefer to make them equivalent, on the principle that all listops
conceptually flatten+concat their arguments first, and then process
each element regardless of its origin.

On the other hand, it can also be argued that

    [,] TERM, TERM, TERM;

is shorthand for

    |(TERM), |(TERM), |(TERM)

and the treatment will depend solely on TERM's scalar-context type
without considering list flattening. Per that interpretation, indeed these
two need not be equivalent:

    my @args = [EMAIL PROTECTED], 1, 2, 3;
    [,] @args;             # four positionals, same as |@args
[,] [EMAIL PROTECTED], 1, 2, 3; # one invocant, three positionals, same as | ([EMAIL PROTECTED]), |(1), |(2), |(3)

however, having a listop that does not do flatten+concat doesn't feel
quite right, so I'd still like the flatten-concat-explode model as currently specced.

Thanks,
Audrey

Reply via email to