in reply to Re^4: Designing a DWIMish interface for generator function
in thread Designing a DWIMish interface for generator function
You assumed that the iterator variable will be created at the same memory address every pass of the loop. It's a bad assumption. For example, the following code is an infinite loop:
my @x; while (deal [1..9] => my ($a,$b,$c) ){ print $a,$b,$c; push @x, \$a; }
Well, maybe not infinite, since deal is leaking memory every pass of the loop...
You assumed that the loop will receive a new iterator each time. It's a bad assumption. For example, deal starts at the wrong number the second and third pass of the outer loop in the following code:
for (1..3) { while (deal [1..9] => my ($a,$b,$c) ){ print $a,$b,$c; last; } }
Just like you need to call keys before each, you'd need to reset the iterator before entering the loop. You'd need
init_deal my ($a,$b,$c) while (deal [1..9] => ($a,$b,$c) ){ ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Designing a DWIMish interface for generator function
by LanX (Saint) on Feb 01, 2010 at 11:12 UTC |