[svn:perl6-synopsis] r13543 - doc/trunk/design/syn
Author: larry Date: Mon Jan 29 10:39:25 2007 New Revision: 13543 Modified: doc/trunk/design/syn/S04.pod Log: Note that take is intended to work en passant as suggested by gabriele renzi++ Also clarified that gather provides a void context to its victim. Modified: doc/trunk/design/syn/S04.pod == --- doc/trunk/design/syn/S04.pod(original) +++ doc/trunk/design/syn/S04.podMon Jan 29 10:39:25 2007 @@ -12,9 +12,9 @@ Maintainer: Larry Wall [EMAIL PROTECTED] Date: 19 Aug 2004 - Last Modified: 25 Jan 2007 + Last Modified: 29 Jan 2007 Number: 4 - Version: 48 + Version: 49 This document summarizes Apocalypse 4, which covers the block and statement syntax of Perl. @@ -435,13 +435,33 @@ explicit because it's not out front where it can be seen. You can, of course, use a placeholder parameter if you also use Creturn.) +=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, its return -value is specified by calling the Ctake function one or more times -within the dynamic scope of the gather. The returned values are in -the form of a lazy multislice, with each dimension corresponding to -one Ctake slice. (A multislice is flattened in most list contexts.). -A Cgather is not considered a loop. +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 gather. 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, +but you may unflatten it again with a @@() contextualizer.) + +Because Cgather evaluates its block or statement in void context, +this typically causes the Ctake statement to be evaluated in void +context. However, a Ctake statement that is not in void context +gathers its arguments Ien passant and also returns them unchanged. +This makes it easy to keep track of what you last took: + +my @uniq = gather for @list { +state $previous = take $_; +next if $_ === $previous; +$previous = take $_; +} + +A Cgather is not considered a loop, but it is easy to combine with a loop +as in the example above. + +=head2 Other Cdo-like forms Other similar CCode-only forms may also take bare statements, including Ctry, Ccontend, Casync, and Clazy. These constructs
Re: [svn:perl6-synopsis] r13543 - doc/trunk/design/syn
On Mon, Jan 29, 2007 at 10:39:27AM -0800, [EMAIL PROTECTED] wrote: +Because Cgather evaluates its block or statement in void context, +this typically causes the Ctake statement to be evaluated in void +context. However, a Ctake statement that is not in void context +gathers its arguments Ien passant and also returns them unchanged. +This makes it easy to keep track of what you last took: + +my @uniq = gather for @list { +state $previous = take $_; +next if $_ === $previous; +$previous = take $_; +} What does it mean for take to be evaluated in void context? What are the gathered values here? take 1, 2; # easy. flattened 1 and then 2, right? @x = take 1, 2; # same thing? $x = take 1, 2; # same thing? [1, 2]? -- Gaal Yahas [EMAIL PROTECTED] http://gaal.livejournal.com/
Re: [svn:perl6-synopsis] r13543 - doc/trunk/design/syn
On Mon, Jan 29, 2007 at 10:01:08PM +0200, Gaal Yahas wrote: +Because Cgather evaluates its block or statement in void context, +this typically causes the Ctake statement to be evaluated in void +context. However, a Ctake statement that is not in void context +gathers its arguments Ien passant and also returns them unchanged. +This makes it easy to keep track of what you last took: + +my @uniq = gather for @list { +state $previous = take $_; +next if $_ === $previous; +$previous = take $_; +} What does it mean for take to be evaluated in void context? What are the gathered values here? take 1, 2; # easy. flattened 1 and then 2, right? @x = take 1, 2; # same thing? $x = take 1, 2; # same thing? [1, 2]? In fact, $x = take 5;# if this were Perl 5, I might expect # either 1 or [1] here! -- Gaal Yahas [EMAIL PROTECTED] http://gaal.livejournal.com/
Re: [svn:perl6-synopsis] r13543 - doc/trunk/design/syn
On Mon, Jan 29, 2007 at 10:08:34PM +0200, Gaal Yahas wrote: On Mon, Jan 29, 2007 at 10:01:08PM +0200, Gaal Yahas wrote: +Because Cgather evaluates its block or statement in void context, +this typically causes the Ctake statement to be evaluated in void +context. However, a Ctake statement that is not in void context +gathers its arguments Ien passant and also returns them unchanged. +This makes it easy to keep track of what you last took: + +my @uniq = gather for @list { +state $previous = take $_; +next if $_ === $previous; +$previous = take $_; +} What does it mean for take to be evaluated in void context? What are the gathered values here? take 1, 2; # easy. flattened 1 and then 2, right? @x = take 1, 2; # same thing? $x = take 1, 2; # same thing? [1, 2]? In fact, $x = take 5;# if this were Perl 5, I might expect # either 1 or [1] here! Ugh, sorry, I meant either 1 or [5]. -- Gaal Yahas [EMAIL PROTECTED] http://gaal.livejournal.com/