Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improves and fixes some errors in the lazy "lists" section
* Changes indexing
* Changes the link to Iterator to a link to Iterable
* Refers generically to objects, not specifically to lists.

This refs #2139, but there's some more work to do. Including,
possibly, moving the whole section to another page, such as Iterators.
  • Loading branch information
JJ committed Jul 3, 2018
1 parent 8e9251b commit a7691be
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions doc/Language/list.pod6
Expand Up @@ -229,16 +229,16 @@ value, but unlike the above options, it will break L<Scalars|/type/Scalar>.
say (1, |$(2, 3), 4) eqv (1, 2, 3, 4); # OUTPUT: «True␤»
say (1, slip($(2, 3)), 4) eqv (1, 2, 3, 4); # OUTPUT: «False␤»
=head1 Lazy Lists
X<|lazy (property of List)>
Lists can be lazy, which means that their values are computed on demand and
stored for later use. To create a lazy list use
L<gather/take|/language/control#gather/take> or the L<sequence
operator|/language/operators#infix_...>. You can also write a class that
implements the role L<Iterable|/type/Iterable> and returns C<True> on a call to
L<is-lazy|/routine/is-lazy>. Please note that some methods like C<elems> cannot
be called on a lazy List and will result in a thrown
X<|laziness in iterable objects>
=head1 Lazy lists
Lists, arrays, sequences and any class with the L<Iterator> role can be lazy,
which means that their values are computed on demand and stored for later use.
To create a lazy object use L<gather/take|/language/control#gather/take> or the
L<sequence operator|/language/operators#infix_...>. You can also write a class
that implements the role L<Iterator|/type/Iterator> and returns C<True> on a
call to L<is-lazy|/routine/is-lazy>. Please note that some methods like C<elems>
cannot be called on a lazy List and will result in a thrown
L<Exception|/type/Exception>.
# This list is lazy and elements will not be available
Expand All @@ -256,9 +256,10 @@ L<Exception|/type/Exception>.
say @no-longer-lazy[];
# OUTPUT: (sequence starting with «[1 11 121» ending with a 300 digit number)
A common use case for lazy Lists are the processing of infinite sequences of numbers,
whose values have not been computed yet and cannot be computed in their entirety.
Specific values in the List will only be computed when they are needed.
A common use case for lazy C<List>s is the processing of infinite sequences of
numbers, whose values have not been computed yet and cannot be computed in their
entirety. Specific values in the List will only be computed when they are
needed.
my @l = 1, 2, 4, 8 ... Inf;
say @l[0..16];
Expand Down

0 comments on commit a7691be

Please sign in to comment.