Use of iterators for state machine (was Re: 2.2 features)

Peter Hansen peter at engcorp.com
Thu Jul 26 01:49:04 EDT 2001


Tim Peters wrote:
> 
> [Nick Perkins]
> > I like generators a lot.  Here's a fun one:
> >
> [...]
> That's something of a strain in such a simple case, but in general the
> ability to "get out of a loop early" without needing to materialize the
> whole sequence first is a major practical application of the iterator
> protocol.

I like the potential for iterators for infinite sequences of several
kinds (where the ability to "get out of a loop early" is an absolute
requirement :-).

I'm especially looking forward to using them to implement state machines.

I suspect they will greatly simplify the readability of several
different state machine patterns I tend to use.  Has anyone with more
of a background in the whole iterator concept (in other languages
of course) tried this before?  Any comments?

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list