Author: audreyt Date: Sat Sep 23 01:05:45 2006 New Revision: 12346 Modified: doc/trunk/design/syn/S03.pod
Log: * S03: Cleanup capture-exploding examples such that |@foo always simply put @foo's elements as positional arguments, regardless of whether @foo[0] contains a Hash. (On the other hand, "[,] @foo" will still happily turn @foo[0] into named argument.) Modified: doc/trunk/design/syn/S03.pod ============================================================================== --- doc/trunk/design/syn/S03.pod (original) +++ doc/trunk/design/syn/S03.pod Sat Sep 23 01:05:45 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 8 Mar 2004 - Last Modified: 20 Sept 2006 + Last Modified: 23 Sept 2006 Number: 3 - Version: 67 + Version: 68 =head1 Changes to Perl 5 operators @@ -911,7 +911,7 @@ as if they'd been placed there directly. @args = [EMAIL PROTECTED],1,2,3; - push [,] @args; # same as push @foo,1,2,3 + push [,] @args; # same as push(@foo: 1,2,3) See S06 for more. @@ -1311,33 +1311,39 @@ is equivalent to: - push @foo, @bar; + push @foo: @bar; -as is this: +which is just another way to write: - my $args = \(@foo, @bar); # construct a Capture object - push |$args; + @foo.push(@bar); -The C<|> sigil functions as a unary form of the C<[,]> -list operator, so we could have written the earlier example as: +The C<|> sigil functions as a unary form of the C<[,]> list operator, +so the examples above can also be written as. - my @args = [EMAIL PROTECTED], @bar; - push |@args; + my $args = \(@foo: @bar); # construct a Capture object + push |$args; # push(@foo: @bar) + +Unlike C<[,]>, C<|> does not flatten its argument, but instead directly +converts its argument into a C<Capture>: + + my @args = \$x, 1, 2, 3; + say [,] @args; # say($x: 1, 2, 3); + say |@args; # say(\$x, 1, 2, 3); -To the extent possible, the C<|> will treat its argument as -a C<Capture> even if it isn't. +Because of this, C<|%args> always produces named arguments, and +C<|@args> always produces positional arguments. In list context, a C<Scalar> holding an C<Array> object does not flatten. Hence $bar = @bar; - push @foo, $bar; + @foo.push($bar); merely pushes a single C<Array> object onto C<@foo>. You can explicitly flatten it in one of these ways: - push @foo, @$bar; - push @foo, $bar[]; - push @foo, |$bar; + @foo.push(@$bar); + @foo.push($bar[]); + @foo.push(|$bar); Those three forms work because the slurpy array in C<push>'s signature flattens the C<Array> object into a list argument. @@ -1382,7 +1388,7 @@ automatically exploded into their various parts, as if you'd said: my \$capture := func(); - push [,] $$capture: @$capture, %$capture; + push($$capture: @$capture, %$capture); or some such. The C<[,]> then handles the various zones appropriately depending on the context. An invocant only makes sense as the first