[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua4.1w4 - for loop with functions - suggestions
- From: Edgar Toernig <froese@...>
- Date: Tue, 26 Mar 2002 18:02:32 +0100
Roberto Ierusalimschy wrote:
>
> > is possible, i would especially like
> >
> > for a,b in MyObject:Get do
>
> You can write
>
> for a,b in MyObject:Get() do ... end
But that wouldn't be the same. You call Get once, the former would
call Get repeatedly (passing MyObject as the first arg each time).
That way you can avoid the creation of a closure. [1]
Ciao, ET.
[1] But then one has to manage the for-state within MyObject which
would prohibit multiple for-loops over the same object at the same time.
I.e. "for a in x:f do for b in x:f do ... end end" would break.
For-loops normally manage iteration state for you. That's not the
case with the for-in-function loop. It has been degenerated to a
simple "while a=f() do...end".