On Sat, Jul 03, 2004 at 01:02:34AM -0600, Luke Palmer wrote:
But indeed there are cases where it is a problem:
my $x = 2;
sub mklist () {
return map { 2 * $_ } 0..10;
}
my @list = mklist;
say @list[0..4]; # 0 2 4 6 8
$x = 1;
say @list; #
Alexey Trofimenko writes:
what I want to ask - would map and grep return an iterators too?.. if
it's true, then previous construct becames very memory efficient, like if
I write
loop ( ... ; ... ; ... ) {...; next if ...; ...; say}
Yep, they will.
hm.. It could be a little too
Alexey Trofimenko wrote:
apply to it perl6 GC, which wouldn't always free memory immediately,
so it could eat 3_000_000 or more.
Parrot runs a DOD (Dead Object Detection) sweep whenever its memory
pools fill up, so this is probably a far smaller problem than you
suggest. (If there still
Brent 'Dax' Royal-Gordon writes:
As you mentioned below, this causes problems if the code in question has
side effects. But there are other cases where it messes up:
sub even($_ = $CALLER::_) { ! $_ % 2 }
my @e=grep { even() } 1..1024;
#Okay, we don't need even anymore...
consider this:
say for map {...} grep {...} map {...} 1..1_000_000
as far as I can imagine, in perl5 it does:
1)flatten 1..1_000_000 into anonimous array; (maybe in this particular
case it is optimized in perl5, like it done in Cforeach.. I don't know.)
2)map trough it elements and store