Help with coroutine-based state machines?

Lulu of the Lotus-Eaters mertz at gnosis.cx
Fri May 30 12:49:58 EDT 2003


Yair Chuchem <yairchu at 012.net.il> wrote previously:
|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:
|Is there something I'm missing?

Almost everything.

Generators serve at least three purposes for state machines:

(1) They avoid function call overhead (much faster)
(2) They let you branch into the middle of an execution context (where
    you left off).
(3) They let you (easily) save local values for when you return to a
    state.

Your approach loses all of those benefits (and doesn't even get rid of
the 'while' loop, just imposes a narrow condition rather than more
flexible breaks from a 'while 1').

Yours, Lulu...

--
 mertz@   _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i
gnosis  _/_/                    Postmodern Enterprises         _/_/  s r
.cx    _/_/  MAKERS OF CHAOS....                              _/_/   i u
      _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/    g s






More information about the Python-list mailing list