Re: C C and lazyness

2004-07-04 Thread Luke Palmer
David Storrs writes: > 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];

Re: C C and lazyness

2004-07-04 Thread David Storrs
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;

Re: C C and lazyness

2004-07-03 Thread Luke Palmer
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..

Re: C C and lazyness

2004-07-03 Thread Jonadab the Unsightly One
Luke Palmer <[EMAIL PROTECTED]> writes: > Well, perhaps not. Theoretically, at this point, $file has been > read completely. It's just that it's lying and it hasn't really. > But if you try to read again, it should resync and things should > work properly. That's all well and good if the fileha

Re: C C and lazyness

2004-07-03 Thread Brent 'Dax' Royal-Gordon
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 isn't

Re: C C and lazyness

2004-07-03 Thread Luke Palmer
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 fun

C C and lazyness

2004-07-02 Thread Alexey Trofimenko
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 C.. I don't know.) 2)map trough it elements and store results in