[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Question about 5.0 for loop
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 06 Jun 2002 14:53:28 -0300
> 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).