Help with coroutine-based state machines?

Terry Reedy tjreedy at udel.edu
Fri May 30 11:15:07 EDT 2003


"Yair Chuchem" <yairchu at 012.net.il> wrote in message
news:3ed72a3c at news.012.net.il...
> How about this implemetation of your state-machine, without the
cluttering
> of the while loops, and as a side effect, without use of generators
too:

In this example, the while loops are certainly not needed.  In a real
example, driven by input, states could be visited many times.  For
that, while loops are needed within generators.  Of course, any
generator *method* can be written as a plain method by rearranging
lines and saving persistent data as instance attributes.  But the
generator form will be faster in repeated execution and may be easier
to write.

Terry J. Reedy






More information about the Python-list mailing list