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

[svn:perl6-synopsis] r12398 - doc/trunk/design/syn

0 views
Skip to first unread message

la...@cvs.perl.org

unread,
Sep 25, 2006, 1:13:24 PM9/25/06
to perl6-l...@perl.org
Author: larry
Date: Mon Sep 25 10:13:23 2006
New Revision: 12398

Modified:
doc/trunk/design/syn/S02.pod
doc/trunk/design/syn/S03.pod
doc/trunk/design/syn/S06.pod

Log:
Slaughter of special [,], now is just listop form of [...]
To support |func() syntax, | is the new * (desigilized)


Modified: doc/trunk/design/syn/S02.pod
==============================================================================
--- doc/trunk/design/syn/S02.pod (original)
+++ doc/trunk/design/syn/S02.pod Mon Sep 25 10:13:23 2006
@@ -12,9 +12,9 @@

Maintainer: Larry Wall <la...@wall.org>
Date: 10 Aug 2004
- Last Modified: 22 Sept 2006
+ Last Modified: 25 Sept 2006
Number: 2
- Version: 71
+ Version: 72

This document summarizes Apocalypse 2, which covers small-scale
lexical items and typological issues. (These Synopses also contain
@@ -670,7 +670,6 @@
@ ordered array
% unordered hash (associative array)
& code/rule/token/regex
- | capture/arguments/match
:: package/module/class/role/subset/enum/type/grammar
@@ multislice view of @

@@ -818,22 +817,14 @@
$$args; # same as "$args as Scalar" or "Scalar($args)"
@$args; # same as "$args as Array" or "Array($args)"
%$args; # same as "$args as Hash" or "Hash($args)"
- |$args; # all of the above

When cast into an array, you can access all the positional arguments; into a
hash, all named arguments; into a scalar, its invocant.

-When stored in a variable using the C<|> sigil, the capture autointerpolates
-into argument lists much like C<@> autoflattens into lists:
-
- |args := \($a, @b, :option($c));
- somefunc(|args); # same as somefunc($a, @b, :option($c))
-
All prefix sigil operators accept one positional argument, evaluated in
scalar context as a rvalue. They can interpolate in strings if called with
parentheses. The special syntax form C<$()> translates into C<$( $/ )>
-to operate on the current match object; the same applies to C<@()>, C<%()> and
-C<|()> forms.
+to operate on the current match object; the same applies to C<@()> and C<%()>.

C<Capture> objects fill the ecological niche of references in Perl 6.
You can think of them as "fat" references, that is, references that
@@ -2153,9 +2144,10 @@

=item *

-The C<[,]> list operator may be used to force list context on its
+The C<|> prefix operator may be used to force "capture" context on its
argument and I<also> defeat any scalar argument checking imposed by
-subroutine signature declarations. This list flattens lazily.
+subroutine signature declarations. Any resulting list arguments are
+then evaluated lazily.

=item *

Modified: doc/trunk/design/syn/S03.pod
==============================================================================
--- doc/trunk/design/syn/S03.pod (original)
+++ doc/trunk/design/syn/S03.pod Mon Sep 25 10:13:23 2006
@@ -12,7 +12,7 @@

Maintainer: Larry Wall <la...@wall.org>
Date: 8 Mar 2004
- Last Modified: 23 Sept 2006
+ Last Modified: 25 Sept 2006
Number: 3
Version: 68

@@ -64,9 +64,8 @@
=item * Unary C<~> now imposes a string (C<Str>) context on its
argument, and C<+> imposes a numeric (C<Num>) context (as opposed
to being a no-op in Perl 5). Along the same lines, C<?> imposes
-a boolean (C<Bool>) context, and the C<[,]> list operator imposes
-a function-arguments (C<Capture>) context on its arguments (as does
-the C<|> sigil when used as an operator).
+a boolean (C<Bool>) context, and the C<|> unary operator imposes
+a function-arguments (C<Capture>) context on its argument.
Unary sigils impose the container context implied by their sigil.
As with Perl 5, however, C<$$foo[bar]> parses as C<( $($foo) )[bar]>,
so you need C<$($foo[bar])> to mean the other way.
@@ -906,14 +905,11 @@
return a boolean for either 1 or 0 arguments. Negated operators
return C<Bool::False>, and all the rest return C<Bool::True>.

-You can also make a reduce operator of the comma operator. This has
-the effect of dereferencing its arguments into another argument list
-as if they'd been placed there directly.
+You can also make a reduce operator of the comma operator. This is just
+the list operator form of the C<< circumfix:<[ ]> >> anonymous array composer:

- @args = \@foo,1,2,3;
- push [,] @args; # same as push(@foo: 1,2,3)
-
-See S06 for more.
+ [1,2,3] # make new Array: 1,2,3
+ [,] 1,2,3 # same thing

You may also reduce using the semicolon second-dimension separator:

@@ -968,7 +964,7 @@
[^^]() # Bool::False
[//]() # undef
[=]() # undef (same for all assignment operators)
- [,]() # ()
+ [,]() # []
[¥]() # []

User-defined operators may define their own identity values, but
@@ -1023,9 +1019,7 @@
and more obviously nonsensical.)

A reduce operator returns only a scalar result regardless of context.
-(Even C<[,]> returns a single C<Capture> object which is then spliced
-into the outer argument list.) To return all intermediate results,
-backslash the operator:
+To return all intermediate results, backslash the operator:

say [\+] 1..* # (1, 3, 6, 10, 15, ...)

@@ -1292,22 +1286,18 @@

Perl 5 forced interpolation of a function's argument list by use of
the C<&> prefix. That option is no longer available in Perl 6, so
-instead the C<[,]> reduction operator serves as an
-interpolator, by casting its operands to C<Capture> objects
-and inserting them into the current argument list.
-
-The C<|> capture sigil may also be used for this when you want to
-interpolate a single item.
-
-Either of these can be used to interpolate an C<Array> or C<Hash>
+instead the C<|> prefix operator serves as an
+interpolator, by casting its operand to a C<Capture> object
+and inserting the capture's parts into the current argument list.
+This operator can be used to interpolate an C<Array> or C<Hash>
into the current call, as positional and named arguments respectively.

-Note that those arguments still must comply with the subroutine's
-signature, but the presence of C<|> or C<[,]> defers that test until run time for
+Note that the resulting arguments still must comply with the subroutine's
+signature, but the presence of C<|> defers that test until run time for
that argument (and for any subsequent arguments):

- my @args = \@foo, @bar;
- push [,] @args;
+ my @args := @foo, @bar;
+ push |@args;

is equivalent to:

@@ -1317,12 +1307,6 @@

@foo.push(@bar);

-The C<|> sigil functions as a unary form of the C<[,]> list operator,
-so the examples above can also be written as.
-
- 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>:

@@ -1371,44 +1355,35 @@
as well as the C<< <> >>, C<< .<> >>, C<«»>, and C<.«»> constant and
interpolating slice subscripting forms.

-The C<[,]> and C<|> operators interpolate lazily for C<Array> and C<Range> objects.
+The C<|> operator interpolates lazily for C<Array> and C<Range> objects.
To get an immediate interpolation like Perl 5 does, add the C<eager> list
operator:

- func([,] 1..Inf); # works fine
- func([,] eager 1..Inf); # never terminates
+ func(|(1..Inf)); # works fine
+ func(|eager 1..Inf); # never terminates (well, actually...)

-To interpolate a function's return value, you must say one of:
+To interpolate a function's return value, you can say:

- push [,] func();
- push |(func());
- push |func(); # WRONG, would parse as (|func).()
+ push |func();

Within such an argument list, function return values are
automatically exploded into their various parts, as if you'd said:

- my \$capture := func();
- push($$capture: @$capture, %$capture);
+ my $capture = \(func());
+ push $$capture: @$capture, %$capture;

-or some such. The C<[,]> then handles the various zones appropriately
+or some such. The C<|> then handles the various zones appropriately
depending on the context. An invocant only makes sense as the first
argument to the outer function call. An invocant inserted anywhere
else just becomes a positional argument at the front of its list,
as if its colon changed back to a comma.

If you already have a capture variable, you can interpolate all of
-its bits at once using the C<< prefix:<|> >> operator (really a sigil).
+its bits at once using the C<< prefix:<|> >> operator:

my \$capture := func();
push |$capture;

-Or you can use the bare sigiled forms:
-
- my |capture := func();
- push |capture;
-
-Bare lvalue capture variables may only be bound, not assigned.
-
=head1 Feed operators

The new operators C<< ==> >> and C<< <== >> are akin to UNIX pipes, but
@@ -1603,7 +1578,7 @@
any all one none
die fail warn
!!! ... ???
- [+] [*] [<] [,] [\+] [\*] etc.
+ [+] [*] [<] [\+] [\*] etc.
(also = as list assignment)
list infix ¥ <== ==> X XX X~X X*X XeqvX etc.
loose and and

Modified: doc/trunk/design/syn/S06.pod
==============================================================================
--- doc/trunk/design/syn/S06.pod (original)
+++ doc/trunk/design/syn/S06.pod Mon Sep 25 10:13:23 2006
@@ -13,7 +13,7 @@

Maintainer: Larry Wall <la...@wall.org>
Date: 21 Mar 2003
- Last Modified: 24 Sept 2006
+ Last Modified: 25 Sept 2006
Number: 6
Version: 58

@@ -373,21 +373,24 @@
doit :123<now>; # always a positional arg

Going the other way, pairs intended as named arguments that don't look
-like pairs must be introduced with the C<[,]> reduction operator or
-the C<|> capture sigil:
+like pairs must be introduced with the C<|> prefix operator:

$pair = :when<now>;
doit $pair,1,2,3; # always a positional arg
- doit |%$pair,1,2,3; # always a named arg
- doit |%(get_pair()),1,2,3; # always a named arg
- doit |%('when' => 'now'),1,2,3; # always a named arg
+ doit |$pair,1,2,3; # always a named arg
+ doit |get_pair(),1,2,3; # always a named arg
+ doit |('when' => 'now'),1,2,3; # always a named arg
+
+Note the parens are necessary on the last one due to precedence.

Likewise, if you wish to pass a hash and have its entries treated as
-named arguments, you must dereference it with a C<[,]> or C<|>:
+named arguments, you must dereference it with a C<|>:

%pairs = {:when<now> :what<any>};
- doit %pairs,1,2,3; # always a positional arg
- doit |%pairs,1,2,3; # always named args
+ doit %pairs,1,2,3; # always a positional arg
+ doit |%pairs,1,2,3; # always named args
+ doit |%(get_pair()),1,2,3; # always a named arg
+ doit |%('when' => 'now'),1,2,3; # always a named arg

Variables with a C<:> prefix in rvalue context autogenerate pairs, so you
can also say this:
@@ -697,10 +700,10 @@
=head2 Argument list binding

The underlying C<Capture> object may be bound to a single scalar
-parameter marked with a C<|> sigil.
+parameter marked with a C<|>.

sub bar ($a,$b,$c,:$mice) { say $mice }
- sub foo (|args) { say |args.perl; &bar.callargs(|args); }
+ sub foo (|$args) { say |$args.perl; &bar.callargs(|$args); }

The C<.callargs> method of C<Code> objects accepts an argument list,
(which can be specified as a Capture object as above), and calls it
@@ -712,19 +715,14 @@
takes a snapshot of what's left of the Capture at that point and then
continues binding as if the Capture parameter weren't there:

- sub compare (|args Num $x, Num $y --> Bool) { ... }
+ sub compare (|$args Num $x, Num $y --> Bool) { ... }

=head2 Flattening argument lists

-The reduce operator C<[,]> casts each of its arguments to a C<Capture>
-object, then splices each of those captures into the argument list
-it occurs in. The unary C<|> sigil has the same effect on a single
-argument.
-
-Casting C<Capture> to C<Capture> is a no-op:
-
- [,](\(1, x=>2)); # Capture, becomes \(1, x=>2)
- |(\(1, x=>2)); # Capture, becomes \(1, x=>2)
+The unary C<|> operator casts its arguments to a C<Capture>
+object, then splices that capture into the argument list
+it occurs in. To get the same effect on multiple arguments you
+can use the C<< |« >> hyperoperator.

C<Pair> and C<Hash> become named arguments:

@@ -734,10 +732,10 @@
C<List> (also C<Seq>, C<Range>, etc.) are simply turned into
positional arguments:

- [,](1,2,3); # Seq, becomes \(1,2,3)
- [,](1..3); # Range, becomes \(1,2,3)
- [,](1..2, 3); # List, becomes \(1,2,3)
- [,]([x=>1, x=>2]); # List (from an Array), becomes \((x=>1), (x=>2))
+ |(1,2,3); # Seq, becomes \(1,2,3)
+ |(1..3); # Range, becomes \(1,2,3)
+ |(1..2, 3); # List, becomes \(1,2,3)
+ |([x=>1, x=>2]); # List (from an Array), becomes \((x=>1), (x=>2))

For example:

@@ -748,12 +746,12 @@
foo(@onetothree); # error: only one arg
foo(|@onetothree); # okay: @onetothree flattened to three args

-The C<[,]> operator flattens lazily -- the array is flattened only if
+The C<|> operator flattens lazily -- the array is flattened only if
flattening is actually required within the subroutine. To flatten before
the list is even passed into the subroutine, use the C<eager> list
operator:

- foo([,] eager @onetothree); # array flattened before &foo called
+ foo(|eager @onetothree); # array flattened before &foo called


=head2 Multidimensional argument list binding
@@ -1919,8 +1917,8 @@

On the caller's end, the C<Capture> is interpolated into any new argument list
much like an array would be, that is, as a scalar in scalar context, and as a
-list in list context. This is the default behavior, but as with an array, the
-caller may use C<< prefix:<[,]> >> or the C<|> sigil to inline the returned values as part of the
+list in list context. This is the default behavior, but the
+caller may use C<< prefix:<|> >> to inline the returned values as part of the
new argument list. The caller may also bind the returned C<Capture> directly.

=head2 The C<caller> function
@@ -2120,7 +2118,7 @@
It can then be passed to C<callargs> using that name:

# Double the return value for &thermo
- &thermo.wrap( -> |args { callargs(|args) * 2 } );
+ &thermo.wrap( -> |$args { callargs(|$args) * 2 } );

In this case only the return value is changed.

@@ -2128,7 +2126,7 @@
C<Code> object by passing the C<Capture> to its C<call> method:

# Transparently redirect all calls to &thermo to &other_thermo
- &thermo.wrap( -> |args { &other_thermo.callargs(|args) } );
+ &thermo.wrap( -> |$args { &other_thermo.callargs(|$args) } );

or more briefly:

@@ -2140,9 +2138,9 @@
As with any return value, you may capture the returned C<Capture> of C<call>
by binding:

- my |retval := callargs(|args);
+ my |$retval := callargs(|$args);
... # postprocessing
- return |retval;
+ return |$retval;

=head2 The C<&?ROUTINE> object

Luke Palmer

unread,
Sep 26, 2006, 3:04:54 AM9/26/06
to la...@cvs.perl.org, perl6-l...@perl.org

> Log:
> Slaughter of special [,], now is just listop form of [...]
> To support |func() syntax, | is the new * (desigilized)

Woohoo! I was about to complain about this whole "capture sigil"
nonsense, but I'm guessing somebody else already did. I also like the
new [,] :-)

Luke

TSa

unread,
Sep 26, 2006, 4:14:22 AM9/26/06
to perl6-l...@perl.org
HaloO,

Luke Palmer wrote:
> Woohoo! I was about to complain about this whole "capture sigil"
> nonsense, but I'm guessing somebody else already did. I also like the
> new [,] :-)

I'm very glad, too. Even though I would like the new operator
spelled / for aesthetic reason.

Regards,
--

Aaron Crane

unread,
Sep 26, 2006, 8:49:42 AM9/26/06
to perl6-l...@perl.org
TSa writes:
> I'm very glad, too. Even though I would like the new operator
> spelled / for aesthetic reason.

I think there'd be problems making that work. It's a prefix operator,
so it has to appear in term position, and we already have terms that
begin with C</>, in the form of regexes. Forcing regexes to always use
the C<m> or C<rx> prefix sounds inadvisable on Huffman grounds.

--
Aaron Crane

0 new messages