Skip to content

Commit 3fcdd25

Browse files
committed
Better example for #2689
1 parent 9a95c73 commit 3fcdd25

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

doc/Language/list.pod6

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,19 @@ very context sensitive on a syntactical level.
363363
364364
When a list appears on the right-hand side of an assignment into a C<@>-sigiled
365365
variable, it is "eagerly" evaluated. This means that a C<Seq> will be iterated
366-
until it can produce no more elements. This is one of the places you do not want
367-
to put an infinite list, lest your program hang and, eventually, run out of memory:
368-
369-
my $i = 3;
370-
my @a = (loop { $i.say; last unless --$i }); # OUTPUT: «3␤2␤1␤»
371-
say "take off!";
366+
until it can produce no more elements. This is one of the places you do not
367+
want to put an infinite list, lest your program hang and, eventually, run out of
368+
memory:
369+
370+
my @divisors = (gather {
371+
for <2 3 5 7> {
372+
take $_ if 70 %% $_;
373+
}
374+
});
375+
say @divisors; # OUTPUT: «[2 5 7]␤»
376+
377+
The L<C<gather> statement\/language/control#index-entry-lazy_list_gather>
378+
creates a lazy list, which is eagerly evaluated when assigned to C<@divisors>
372379
373380
=head2 Flattening "context"
374381

0 commit comments

Comments
 (0)