Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Better example for #2689
  • Loading branch information
JJ committed Mar 26, 2019
1 parent 9a95c73 commit 3fcdd25
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions doc/Language/list.pod6
Expand Up @@ -363,12 +363,19 @@ very context sensitive on a syntactical level.
When a list appears on the right-hand side of an assignment into a C<@>-sigiled
variable, it is "eagerly" evaluated. This means that a C<Seq> will be iterated
until it can produce no more elements. This is one of the places you do not want
to put an infinite list, lest your program hang and, eventually, run out of memory:
my $i = 3;
my @a = (loop { $i.say; last unless --$i }); # OUTPUT: «3␤2␤1␤»
say "take off!";
until it can produce no more elements. This is one of the places you do not
want to put an infinite list, lest your program hang and, eventually, run out of
memory:
my @divisors = (gather {
for <2 3 5 7> {
take $_ if 70 %% $_;
}
});
say @divisors; # OUTPUT: «[2 5 7]␤»
The L<C<gather> statement\/language/control#index-entry-lazy_list_gather>
creates a lazy list, which is eagerly evaluated when assigned to C<@divisors>
=head2 Flattening "context"
Expand Down

0 comments on commit 3fcdd25

Please sign in to comment.