[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question about 5.0 for loop
- From: Tom Wrensch <twrensch@...>
- Date: Thu, 6 Jun 2002 11:22:41 -0700 (PDT)
Thanks, I'd misread "explist" as just the function. You'd think I'd notice
the "list" part! It makes a lot more sense now.
- Tom
On Thu, 6 Jun 2002, Roberto Ierusalimschy wrote:
> > But I don't see any way _s could ever be modified
>
> It is not. Maybe the name "state" is misleading. Actually, there are two
> "states": _s and `var1'. _s is fixed (e.g. the table or the file you are
> traversing), while `var1' varies.
>
> Notice that we start with
>
> > local _f, _s, var_1 = explist
>
> so we do have a way to assign a value to _s. nexti(t), for instance,
> returns a function *and* `t' ;-)
>
> For several simple iterations such state is enough (e.g. traversing tables,
> reading the lines of a file, etc.). For more complex ones, you can
> either use a closure or put a table in _s (and as much state as you want
> inside the table).
>
> -- Roberto
>