[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: iterators
- From: spir <denis.spir@...>
- Date: Fri, 13 Nov 2009 11:00:17 +0100
Hello,
I find great that lua introduced proper iterators, including generators, without addition of any new language feature such as continuations and magic "yield" statements. Actually, the magic is rather done by lua under the hood but does not directly affect the user --if I understand correctly.
Still, after a first lucky trial, I had rather hard and long time guessing how to properly interpret the syntax (esp the "invisible" variables) and consequentely how to implement iterators for various uses -- esp. the highly different cases of collection and generator iterators, respectively. I was surprised to endly discover that defining the iterator func (the actual data yielding one) inside the iterator allows getting rid of the said invisible vars alltogether.
I may be wrong, sure, maybe in some cases they are needed, still maybe we could simplify the syntax in a way that would let using this great feature much more easily. I wrote a doc about this, but put it on the wiki for it's rather long:
http://lua-users.org/wiki/SimplerForIterator
(Took a risk if I'm totally wrong ;-) & hope it's not full of stupidity, because there it will remain -- but anyway a wiki is intended to be corrected.)
Denis
--------------------------------
* la vita e estrany *
site: http://spir.wikidot.com/