Author: audreyt
Date: Wed Apr  2 10:22:01 2008
New Revision: 14536

Modified:
   doc/trunk/design/syn/S04.pod

Log:
* S04: Create a new section, "Statement-level bare blocks"
  since its content doesn't really belong in the "do-once loop"
  section.

* S04: Also, clarify that statement-level blocks with placeholder
  variables should trigger an error, unless prefixed with "do"
  or postfixed with a modifier.


Modified: doc/trunk/design/syn/S04.pod
==============================================================================
--- doc/trunk/design/syn/S04.pod        (original)
+++ doc/trunk/design/syn/S04.pod        Wed Apr  2 10:22:01 2008
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall <[EMAIL PROTECTED]>
   Date: 19 Aug 2004
-  Last Modified: 8 Feb 2008
+  Last Modified: 2 Apr 2008
   Number: 4
-  Version: 64
+  Version: 65
 
 This document summarizes Apocalypse 4, which covers the block and
 statement syntax of Perl.
@@ -533,15 +533,6 @@
 useful for the do-once block, since it is offically a loop and can take
 therefore loop control statements.
 
-Although a bare block is no longer a do-once loop, it still executes
-immediately as in PerlĀ 5, as if it were immediately dereferenced with
-a C<.()> postfix, so within such a block C<CALLER::> refers to the
-scope surrounding the block.  If you wish to return a closure from a
-function, you must use an explicit prefix such as C<return> or C<sub>
-or C<< -> >>.  (Use of a placeholder parameter is deemed insufficiently
-explicit because it's not out front where it can be seen.  You can, of
-course, use a placeholder parameter if you also use C<return>.)
-
 Another consequence of this is that any block just inside a
 left parenthesis is immediately called like a bare block, so a
 multidimensional list comprehension may be written using a block with
@@ -553,6 +544,32 @@
 
     @names = ({ "$^name.$^num" } for 'a'..'zzz' X 1..100);
 
+=head2 Statement-level bare blocks
+
+Although a bare block occuring as a single statement is no longer
+a do-once loop, it still executes immediately as in PerlĀ 5, as if it
+were immediately dereferenced with a C<.()> postfix, so within such a
+block C<CALLER::> refers to the scope surrounding the block.
+
+If you wish to return a closure from a function, you must use an
+explicit prefix such as C<return> or C<sub> or C<< -> >>.
+
+Use of a placeholder parameter in statement-level blocks triggers a
+syntax error, because the parameter is not out front where it can be
+seen.  However, it's not an error when prefixed by a C<do>, or when
+followed by a statement modifier:
+
+    # Syntax error: Statement-level placeholder block
+    { say $^x };
+
+    # Not an syntax error, though $x doesn't get the argument it wants
+    do { say $^x };
+
+    # Not an error: Equivalent to "for 1..10 -> $x { say $x }"
+    { say $^x } for 1..10;
+
+    # Not an error: Equivalent to "if foo() -> $x { say $x }"
+    { say $^x } if foo();
 
 =head2 The gather statement
 

Reply via email to