Author: larry
Date: Thu Feb  8 13:52:24 2007
New Revision: 13577

Modified:
   doc/trunk/design/syn/S04.pod
   doc/trunk/design/syn/S05.pod
   doc/trunk/design/syn/S06.pod
   doc/trunk/design/syn/S12.pod

Log:
Unified proto processing to implicitly allow redeclarations within scope.
This works on most declarators, including regex, token, rule, and variables.
Multiple my declarations warn about redeclaration as suggested by lukastic++.
This may be suppressed with a "proto" declaration of the variable.
The "multi" keyword is now optional in the scope of a proto.
The "unique" keyword now "undoes" an outer "proto".


Modified: doc/trunk/design/syn/S04.pod
==============================================================================
--- doc/trunk/design/syn/S04.pod        (original)
+++ doc/trunk/design/syn/S04.pod        Thu Feb  8 13:52:24 2007
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall <[EMAIL PROTECTED]>
   Date: 19 Aug 2004
-  Last Modified: 29 Jan 2007
+  Last Modified: 8 Feb 2007
   Number: 4
-  Version: 50
+  Version: 51
 
 This document summarizes Apocalypse 4, which covers the block and
 statement syntax of Perl.
@@ -75,6 +75,15 @@
     my $x;
     my $x;
 
+By default the second declaration will get a compiler warning.
+You may suppress this by modifying the first declaration
+with C<proto>:
+
+    my proto $x;
+    ...
+    while my $x = @x.shift {...}              # no warning
+    while my $x = @x.shift {...}              # no warning
+
 If you've referred to C<$x> prior to the first declaration, and the compiler
 tentatively bound it to C<$OUTER::x>, then it's an error to declare it, and
 the compiler is required to complain at that point.  If such use can't

Modified: doc/trunk/design/syn/S05.pod
==============================================================================
--- doc/trunk/design/syn/S05.pod        (original)
+++ doc/trunk/design/syn/S05.pod        Thu Feb  8 13:52:24 2007
@@ -14,9 +14,9 @@
    Maintainer: Patrick Michaud <[EMAIL PROTECTED]> and
                Larry Wall <[EMAIL PROTECTED]>
    Date: 24 Jun 2002
-   Last Modified: 5 Feb 2007
+   Last Modified: 8 Feb 2007
    Number: 5
-   Version: 50
+   Version: 51
 
 This document summarizes Apocalypse 5, which is about the new regex
 syntax.  We now try to call them I<regex> rather than "regular
@@ -670,17 +670,19 @@
 
 =item *
 
-Alternatively, if you predeclare a category, you can write multiple
-rules for the same category, differentiated only by the symbol they
+Alternatively, if you predeclare a proto regex, you can write multiple
+regexes for the same category, differentiated only by the symbol they
 match:
 
-    category sigil;
-    token sigil { :<$> }
-    token sigil { :<@> }
-    token sigil { :<@@> }
-    token sigil { :<%> }
-    token sigil { :<&> }
-    token sigil { :<::> }
+    proto token sigil;
+    multi token sigil { :<$> }
+    multi token sigil { :<@> }
+    multi token sigil { :<@@> }
+    multi token sigil { :<%> }
+    multi token sigil { :<&> }
+    multi token sigil { :<::> }
+
+(The C<multi> is optional and generally omitted with a grammar.)
 
 This can be viewed as a form of multiple dispatch, except that it's
 based on longest-token matching rather than signature matching.  The
@@ -688,6 +690,11 @@
 rules to the same category in a derived grammar.  All of them will
 be matched in parallel when you try to match C<< /<sigil>/ >>.
 
+If there are formal parameters on multi regex methods, matching
+still proceeds via longest-token rules first.  If that results in a
+tie, a normal multiple dispatch is made using the arguments to the
+remaining variants, assuming they can be differentiated by type.
+
 =item *
 
 An interpolated hash matches the longest possible token.  The match

Modified: doc/trunk/design/syn/S06.pod
==============================================================================
--- doc/trunk/design/syn/S06.pod        (original)
+++ doc/trunk/design/syn/S06.pod        Thu Feb  8 13:52:24 2007
@@ -58,7 +58,11 @@
 
 B<Prototypes> (keyword: C<proto>) specify the commonalities (such
 as parameter names, fixity, and associativity) shared by all multis
-of that name in the scope of the C<proto> declaration.
+of that name in the scope of the C<proto> declaration.  A C<proto>
+also forces all routines of the same short name within the scope to
+be considered C<multi> whether they are explicitly declared so or not.
+(This is particularly useful when adding to rule sets or when attempting
+to compose conflicting methods from roles.)
 
 A modifier keyword may occur before the routine keyword in a named routine:
 

Modified: doc/trunk/design/syn/S12.pod
==============================================================================
--- doc/trunk/design/syn/S12.pod        (original)
+++ doc/trunk/design/syn/S12.pod        Thu Feb  8 13:52:24 2007
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall <[EMAIL PROTECTED]>
   Date: 27 Oct 2004
-  Last Modified: 3 Feb 2007
+  Last Modified: 8 Feb 2007
   Number: 12
-  Version: 38
+  Version: 39
 
 =head1 Overview
 
@@ -729,7 +729,15 @@
 of its invocant arguments.  The "short name" doesn't.  If you put
 C<multi> in front of any sub (or method) declaration, it allows
 multiple long names to share a short name, provided all of them are
-declared C<multi>.  A sub (or method) without a C<multi> doesn't share
+declared C<multi>.  (Putting C<proto> on the first such declaration has
+the same effect, but usually you want to put the C<multi> explicitly
+anyway for documentation.)  If a sub (or method) is not marked
+with C<multi> or within the scope of a C<proto>, it is considered a
+I<unique> sub.  You may mark a sub explicitly as C<unique> as well, if
+you're worried it might be within the scope of a C<proto>, and want there
+to be only one such routine within this scope.
+
+A unique sub (or method) doesn't share
 with anything outside of it or declared prior to it.  Only one such
 sub (or method) can inhabit a given namespace, and it hides any outer
 subs (or less-derived methods) of the same short name.  It may share
@@ -1066,11 +1074,11 @@
 Alternately, if the role's methods are declared C<multi>, they can be
 disambiguated based on their long name.  If the roles forget to declare
 them as multi, you can force a multi on the roles' methods by installing
-a multi stub in the class being constructed:
+a proto stub in the class being constructed:
 
-    multi method shake {...}
+    proto method shake {...}
 
-A proto method also works, and will be called if the multi fails:
+The proto method will be called if the multi fails:
 
     proto method shake { warn "They couldn't decide" }
 
@@ -1082,7 +1090,7 @@
     class DogTree {
         does DogBark;
         does TreeBark;
-        multi method bark {...}
+        proto method bark {...}
         ...
     }
 

Reply via email to