Re: '__iter', yet again!
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: '__iter', yet again!
- From: Roberto Ierusalimschy <roberto@...>
- Date: 2009年12月16日 16:01:24 -0200
> I am in two minds between table.foreach and Generic For with __iter, but I
> find Generic For without __iter to be a rather half-assed implementation!
table.foreach allows different iterations over a table (e.g.,
table.foreachi), while __iter does not.
About the choice between iterators (table.foreach) and generators
(pairs(table)): iterators are easier to write but generators are
more flexible to use. (See the famous "same fringe problem".)
Coroutines make trivial to convert an iterator into a generator, so we
can have the best of both worlds: you write an iterator and use it as
a generator. So, Lua favors the use of generators, through the generic
for.
-- Roberto
- References:
- Re: '__iter', yet again!, Jerome Vuarand
- Re: '__iter', yet again!, Jerome Vuarand
- Re: '__iter', yet again!, Luiz Henrique de Figueiredo
- Re: '__iter', yet again!, steve donovan
- RE: '__iter', yet again!, John Hind