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

2007-01-29 Thread larry
Author: larry
Date: Mon Jan 29 14:06:49 2007
New Revision: 13545

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

Log:
Clarifications requested by gaal++.


Modified: doc/trunk/design/syn/S04.pod
==
--- doc/trunk/design/syn/S04.pod(original)
+++ doc/trunk/design/syn/S04.podMon Jan 29 14:06:49 2007
@@ -438,12 +438,19 @@
 =head2 The gather statement
 
 A variant of Cdo is Cgather.  Like Cdo, it is followed by a
-statement or block, and executes it once.  Unlike Cdo, it evaluates the
-statement or block in void context; its return
-value is instead specified by calling the Ctake function one or more times
-within the dynamic scope of the Cgather.  The returned values are in the
-form of a lazy multislice, with each slice corresponding to one
-Ctake capture.  (A multislice is lazily flattened in normal list context,
+statement or block, and executes it once.  Unlike Cdo, it evaluates
+the statement or block in void context; its return value is instead
+specified by calling the Ctake list prefix operator one or more times
+within the dynamic scope of the Cgather.  The Ctake function's
+signature is like that of Creturn; it merely captures the CCapture
+of its argments without imposing any additional constraints (in the
+absense of context propagation by the optimizer).  The value returned
+by the Ctake to its own context is that same CCapture object (which
+is ignored when the Ctake is in void context).  Regardless of the
+Ctake's context, the CCapture object is also added to the list of
+values being gathered, which is returned by the Cgather in the form
+of a lazy multislice, with each slice corresponding to one Ctake
+capture.  (A multislice is lazily flattened in normal list context,
 but you may unflatten it again with a C@@() contextualizer.)
 
 Because Cgather evaluates its block or statement in void context,
@@ -458,8 +465,34 @@
 $previous = take $_;
 }
 
+The Ctake function essentially has two contexts simultaneously, the
+context in which the gather is operating, and the context in which the
+Ctake is operating.  These need not be identical contexts, since they
+may bind or coerce the resulting captures differently:
+
+my @y;
+@x = gather for 1..2 {  # @() context for list of captures
+my $x = take $_, $_ * 10;   # $() context for individual capture
+push @y, $x;
+}
+# @x returns 1,10,2,20
+# @y returns [1,10],[2,20]
+
+Likewise, we can just remember the gather's result by binding and
+later coerce it:
+
+$c := gather for 1..2 {
+take $_, $_ * 10;
+}
+# @$c returns 1,10,2,20
+# @@$c returns [1,10],[2,20]
+# $$c returns [[1,10],[2,20]]
+
+Note that the Ctake itself is in void context in this example because
+the Cfor loop is in void context.
+
 A Cgather is not considered a loop, but it is easy to combine with a loop
-as in the example above.
+statement as in the examples above.
 
 =head2 Other Cdo-like forms
 


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

2007-01-29 Thread Gaal Yahas
On Mon, Jan 29, 2007 at 02:06:51PM -0800, [EMAIL PROTECTED] wrote:
 +The Ctake function essentially has two contexts simultaneously, the
 +context in which the gather is operating, and the context in which the
 +Ctake is operating.  These need not be identical contexts, since they
 +may bind or coerce the resulting captures differently:
 +
 +my @y;
 +@x = gather for 1..2 {  # @() context for list of captures
 +my $x = take $_, $_ * 10;   # $() context for individual capture
 +push @y, $x;
 +}
 +# @x returns 1,10,2,20
 +# @y returns [1,10],[2,20]

XXX = gather {
YYY
take f();
ZZZ
}

sub f () {
return want.Scalar ?? 42 !! 54;
}

Which of XXX, YYY, and ZZZ influence whether the taken value is 42 or
54? Please confirm there's *no way* that f is entered twice here :-)

(If I'm following correctly, then take's args are basically evaluated
in list context. If YYY is something like $scalar =  that list gets
Captured, but there's still a list there.)

-- 
Gaal Yahas [EMAIL PROTECTED]
http://gaal.livejournal.com/


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

2007-01-29 Thread Brandon S. Allbery KF8NH


On Jan 29, 2007, at 17:06 , [EMAIL PROTECTED] wrote:


+absense of context propagation by the optimizer).  The value returned


Minor spelling nit:  absence

--
brandon s. allbery[linux,solaris,freebsd,perl] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH