Lazy lists (II)
- Perl 6 lists are lazily evaluated
- As long as you don't ask for the last element, infinite lists are fine
- Use binding (
:=
) to assign them to variables
-
my @fib := 1, 1, * + * ... *
- If I then ask for
@fib[40]
, enough elements are generated to get to the 41st Fibonacci number
- Those generated elements are remembered
- Though in the future, if a list is not bound to a variable, earlier values may be forgotten
« first
< prev
(32 / 41)
next >
last »