develooper Front page | perl.perl6.language | Postings from April 2005

Lazy Lists + Mutable Arrays + Garbage Collection

Thread Next
Brad Bowman
April 24, 2005 01:11
Lazy Lists + Mutable Arrays + Garbage Collection
Message ID:


I've been wondering how to lazy lists will work.
The answer "Correctly, don't worry about it", is entirely acceptable...

The intent of this example in S06 seems clear, make @oddsquares
a lazily filled array of squares of odd @nums:

 S06/Pipe operators

  It [==>] binds the (potentially lazy) list from the blunt end 
  to the slurpy parameter(s) of the subroutine on the sharp end. 

  If the operand on the sharp end of a pipe is not a call to a 
  variadic operation, it must be a variable, in which case the 
  list value is assigned to the variable. This special case 
  allows for "pure" processing chains:

  @oddsquares <== map { $_**2 } <== sort <== grep { $_ % 2 } <== @nums;

So @oddsquares is like a stream of values derived from @nums.  (is it?)
Then presumably I can make a @primesquares stream:

  my (@ints, @primesquares);
  @ints <== 2...;
  @primesquares <== map { $_**2 } <== grep { is_prime($_) } <== @ints;

  say @primesquares[3];

Can I then treat @primesquares like an array, say by swapping
two elements?  How about @ints?

If these arrays can be be mutated then how can they be garbage
collected?  All the non-prime @ints could be still hanging around
while either array is in scope.

With cons based lists, past stream values are no longer referred to
so can be reclaimed, but we have random access arrays.

That's about where my wondering stopped.


I always get nervous when this sig appears "randomly"...
 There are times when a person gets carried away and talks on without
 thinking too much. But this can be seen by observers when one's mind is
 flippant and lacking truth. -- Hagakure

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About