A minor point, a capture-of-captures is different from an
array-of-arrays (at least it was a few months ago), and the array
assignment flattens a capture-of-captures into a flat array. If you
want to preserve the capture structure, use
"my @@stuff = gather ..."
... but rakudo doesn't seem to support the "@@" syntax, which as
Patrick notes is amongst items under reconstruction.

On Tue, Jul 21, 2009 at 4:19 PM, Minimiscience<minimiscie...@gmail.com> wrote:
> When "take" is called on a variable that is later modified, is the Capture
> returned by the enclosing "gather" supposed to reflect the change or not?  I
> know that Captures are the Perl 6 equivalent of references, but it seems
> natural to expect the contents to be copied by value at some point prior to
> the variables being modified.
>
> As an example, what is the output of the below program supposed to be?  On
> Rakudo (which doesn't seem to support multidimensional captures properly),
> it's "[20, 21, 22, 20, 21, 22, 20, 21, 22, 20, 21, 22]" instead of the
> desired "[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16,
> 17, 18, 19]]". ...
>
> #!/usr/bin/env perl6
> use v6;
> my @stuff = gather {
>  my @things;
>  for ^23 {
> �...@things.push: $_;
>  if @things == 5 {
>   take @things;
>   @things = ();
>  }
>  }
> }
> say @stuff.perl;
> __END__
>
> -- Minimiscience
>

Reply via email to