Author: larry
Date: Mon Feb 12 00:10:05 2007
New Revision: 13582
Modified:
doc/trunk/design/syn/S02.pod
doc/trunk/design/syn/S04.pod
doc/trunk/design/syn/S06.pod
Log:
The kludge known as "leave" is now spelled "give".
The give() function always gives the final value of the innermost block.
The $context.give() method always gives the final value of the context.
Rather than repeating the context selector interface we now rely on object.
Loop labels are now considered sufficient OO to allow LABEL.give($retval)
within the *lexical* scope of the labeled statement.
Modified: doc/trunk/design/syn/S02.pod
==
--- doc/trunk/design/syn/S02.pod(original)
+++ doc/trunk/design/syn/S02.podMon Feb 12 00:10:05 2007
@@ -12,9 +12,9 @@
Maintainer: Larry Wall <[EMAIL PROTECTED]>
Date: 10 Aug 2004
- Last Modified: 8 Feb 2007
+ Last Modified: 11 Feb 2007
Number: 2
- Version: 85
+ Version: 86
This document summarizes Apocalypse 2, which covers small-scale
lexical items and typological issues. (These Synopses also contain
@@ -2468,7 +2468,21 @@
The lexical routine itself is C<&?ROUTINE>; you can get its name with
C<&ROUTINE.name>. The current block is C<&?BLOCK>. If the block has a label,
-that shows up in C<&?BLOCK.label>.
+that shows up in C<&?BLOCK.label>. Within the lexical scope of
+a statement with a label, the label is a pseudo-object representing
+the dynamic context of that statement. (If inside multiple dynamic
+instances of that statement, the label represents the innermost one.)
+When you say:
+
+next LINE;
+
+it is really a method on this pseudo-object, and
+
+LINE.next;
+
+would work just as well. You can exit any labeled block early by saying
+
+MyLabel.give(@results);
=item *
Modified: doc/trunk/design/syn/S04.pod
==
--- doc/trunk/design/syn/S04.pod(original)
+++ doc/trunk/design/syn/S04.podMon Feb 12 00:10:05 2007
@@ -12,9 +12,9 @@
Maintainer: Larry Wall <[EMAIL PROTECTED]>
Date: 19 Aug 2004
- Last Modified: 8 Feb 2007
+ Last Modified: 11 Feb 2007
Number: 4
- Version: 51
+ Version: 52
This document summarizes Apocalypse 4, which covers the block and
statement syntax of Perl.
@@ -204,7 +204,8 @@
within the body of the loop. See below.
The value of a loop statement is the list of values from each
-iteration. (This list is actually a multidimensional list (a "multislice")
+iteration that successfully completed without a C or C.
+(This list is actually a multidimensional list (a "multislice")
with dimensional boundaries at each iteration. Most list contexts
ignore these boundaries and flatten the list.) If you do not wish
to accidentally return a list from the final loop statement in a
@@ -651,26 +652,49 @@
with the C, C, or C keywords). Pointy blocks
and bare closures are transparent to C. If you pass a closure
object outside of its official "sub" scope, it is illegal to
-return from it. You may only leave the closure block itself with C
-or by falling off the end of it.
+return from it. You may only leave the displaced closure block itself
+by falling off the end of it or by explicitly calling C.
-To return a value from a pointy block or bare closure, you either
-just let the block return the value of its final expression, or you can
-use C. A C by default exits from the innermost block.
-But you may change the behavior of C with a selector as the
-first argument:
+To return a value from any pointy block or bare closure, you either
+just let the block return the value of its final expression, or you
+can use C, which comes in both function and method forms.
+The function (or listop) form always exits from the innermost block,
+returning its arguments as the final value of the block exactly as
+return does. The method form will leave any block in the dynamic
+scope that can be named as an object and that responds to the C<.give>
+method.
-leave Loop where { .label ~~ 'LINE' }, 1,2,3;
+Hence, the C function:
-The innermost block matching the selection criteria will be exited.
-The return value, if any, must be passed as the second and subsequent
arguments.
-To return pairs as part of the value, you can use a feed operator:
+give(1,2,3)
-leave <== :foo:bar:baz(1) if $leaving;
+is really just short for:
-or going the other way:
+$?BLOCK.give(1,2,3)
-$leaving and :foo:bar:baz(1) ==> leave;
+To return from your immediate caller, you can say:
+
+caller.give(1,2,3)
+
+Further contexts up the caller stack may be located by the selector
+that is built into the C function itself:
+
+caller({ .label eq 'LINE' }).give(1,2,3);
+
+By default the innermost dynamic scope matching the selection criteria
+will be exited. This can be a bit cumbersome, so in the particular
+case of labels, the label that is already vi