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

Lazy Lists + Mutable Arrays + Garbage Collection

Thread Next
From:
Brad Bowman
Date:
April 24, 2005 01:11
Subject:
Lazy Lists + Mutable Arrays + Garbage Collection
Message ID:
1114330227.4176.83.camel@oxum

Hi,

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.


Brad


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 http://bereft.net/hagakure/


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About