lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> 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

-- Roberto