Jim Weirich wrote:

> 
> Python (tends) to use a style of iteration I call external iterators
> (terminology in the industry varies, so be aware).  The C language
> designers noticed that a loop can be defined by initialize / test /
> increment code fragments.  Likewise, an external iterator captures these
> operations as methods in an object.  In Python (IIRC) the next() method
> both returns the next object and advances the iterator and an exception
> is used to signal the end of the iteration.

True.

> An external iterator object keeps its state separate from the object it
> is iterating.  Multiple external iterators (referencing the same
> collection) may exist at any one time.  The user may call next
> explicitly, but I believe that Python is knowledgable about iterators
> and will automatically use an iterator in a for statement.

True.

> External iterators are conceptually simple and easy to use.  Many
> languages (e.g. C++, Java) use this style of iterator.

Yes, but the "for" loop doesn't know what you're doing so the syntax is 
gross. Even moreso in Java than C++ IIRC.

> ...
> This is possible in Ruby, but it requires that we be able to return from
> a function in such a way we can resume the function at the return point
> (exactly as generators do).  We don't have generators in Ruby, but we do
> have a very powerful, mind-bending capability called continuations. 
> Someday I would like to write up how do use continutations to do this,
> but this note is already too long.  Suffice it to say that we can use
> continuations to implement generator capability in about 20 lines of
> code.  

http://www.rubygarden.org/ruby?RubyFromPython

" In many cases, the role of Python's simple generators is already 
filled by regular Ruby iterators (as demonstrated in the previous 
section). For more complicated cases you may instead want to use 
Continuations. The following code was grabbed from [Hipster's home 
page], and he says that he got it from a ruby-talk post, so the original 
author is unknown. For starters, though, here's a general-purpose 
generator class in Ruby: "

  Paul Prescod