lua-users home
lua-l archive

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

>> Why would anyone assume that coroutines have something to do with
>> iterators beats the life out of me.
> The Lua5 manual begins its definition of coroutines this way:
>       Lua supports coroutines, also called semi-coroutines, generators, or
>       colaborative multithreading.
> And describes the new "for" syntax this way:
>       The generic for statement works over functions, called generators.
>       It calls its generator to produce a new value for each iteration,
>       stopping when the new value is nil.

I had exactly the same thought as you when I first read the Lua5.0 manual
(including the feeling of inefficiency). Closer examination showed it not to
be the case BUT the manual is VERY misleading in this area... using the word
"generator" in both contexts without disclaimer.

This is especially confusing since both features are new to version 5, and
languages such as Icon _do_ use coroutine generators to drive their "for"

With the introduction of coroutines to Lua, the section of the manual
dealing with the "for" statement needs to be cleaned up. It needs to
explicitly give some sort of title to 'next-index' functions such as "next",
as well as iteration setup functions such as "pair" (if they even need to be
kept at all). It also needs to point out that these are not related to
coroutines (even if the titles, such as 'generator' or 'iterator' are often
associated with them).

> So that's why I think that Lua5 is headed toward using coroutines for
> iterators.

Luckily I don't think that's the plan. *whew*

Peter Hill.