lua-users home
lua-l archive

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


IBM developWorks has run a series of articles on Python's generators, which is basically the same construct as the semi-coroutines in the development version of Lua. Note that in Python, any function containing a yield becomes a coroutine automatically (a point which the author doesn't seem to like), while in Lua coroutines must be created explicitly.

Fun stuff...

-John


"Iterators and simple generators", David Mertz
Python 2.2 introduces a new construct accompanied by a new keyword. The construct is generators, the keyword is yield. Generators make possible several new, powerful, and expressive programming idioms, but are also a little bit hard to get one's mind around at first glance. In this article, David provides a gentle introduction to generators, and also to the related topic of iterators.
<http://www-106.ibm.com/developerworks/opensource/library/l-pycon.html>

"Generator-based state machines", David Mertz
Introduced in Python 2.2, simple generators may be used to simplify state machines and to simulate coroutines. Coroutines are an exotic flow mechanism that few widely used languages -- not even non-Stackless Python -- allow. Python's new generators, however, get you almost all the way to coroutines, and the extra few steps can be faked.
<http://www-106.ibm.com/developerworks/opensource/library/l-pygen.html>

"Implementing 'weightless threads' with Python generators", David Mertz
David Mertz introduces weightless threads. Similar to Stackless Python microthreads, but using standard Python 2.2 -- they allow for extremely large numbers of cooperating processes with virtually no overhead.
<http://www-106.ibm.com/developerworks/opensource/library/l-pythrd.html>


--
http:// i      .   /