Author: larry
Date: Mon May 28 12:14:12 2007
New Revision: 14402

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

Log:
Clarifications to conditional bindings suggested by xinming++ and gaal++.


Modified: doc/trunk/design/syn/S04.pod
==============================================================================
--- doc/trunk/design/syn/S04.pod        (original)
+++ doc/trunk/design/syn/S04.pod        Mon May 28 12:14:12 2007
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall <[EMAIL PROTECTED]>
   Date: 19 Aug 2004
-  Last Modified: 17 Apr 2007
+  Last Modified: 28 May 2007
   Number: 4
-  Version: 57
+  Version: 58
 
 This document summarizes Apocalypse 4, which covers the block and
 statement syntax of Perl.
@@ -211,6 +211,24 @@
 false, might nevertheless be an I<interesting> value of false.  (By similar
 reasoning, an C<unless> allows binding of a false parameter.)
 
+An explicit placeholder may also be used:
+
+    if blahblah() { return $^it }
+
+However, use of C<$_> with a conditional statement's block is I<not>
+considered sufficiently explicit to turn a 0-ary block into a 1-ary
+function, so both these methods use the same invocant:
+
+    if .haste { .waste }
+
+(Contrast with a non-conditional statement such as:
+
+    for .haste { .waste }
+
+where each call to the block would bind a new invocant for the
+C<.waste> method, each of which is likely different from the original
+invocant to the C<.hast> method.)
+
 Conditional statement modifiers work as in PerlĀ 5.  So do the
 implicit conditionals implied by short-circuit operators.  Note though that
 the first expression within parens or brackets is parsed as a statement,
@@ -253,13 +271,15 @@
         ...
     }
 
-You may optionally bind the result of the conditional expression to a
-parameter of the block:
+As with conditionals, you may optionally bind the result of the
+conditional expression to a parameter of the block:
 
     while something() -> $thing {
         ...
     }
 
+    while something() -> { ... $^thing ... }
+
 Nothing is ever bound implicitly, however, and many conditionals would
 simply bind True or False in an uninteresting fashion.  This mechanism
 is really only good for objects that know how to return a boolean
@@ -491,6 +511,18 @@
 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
+multiple parameters fed by a C<for> modifier:
+
+    @names = (-> $name, $num { "$name.$num" } for 'a'..'zzz' X 1..100);
+
+or equivalently, using placeholders:
+
+    @names = ({ "$^name.$^num" } for 'a'..'zzz' X 1..100);
+
+
 =head2 The gather statement
 
 A variant of C<do> is C<gather>.  Like C<do>, it is followed by a

Reply via email to