generator/coroutine terminology

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Mar 16 10:36:38 EDT 2015


On Tue, 17 Mar 2015 01:35 am, Steven D'Aprano wrote:

> On Tue, 17 Mar 2015 01:19 am, Rustom Mody wrote:
> 
>> On Monday, March 16, 2015 at 7:10:03 PM UTC+5:30, Steven D'Aprano wrote:
>>> And of course, from a comp science theoretic perspective,
>>> generators are a kind of subroutine, not a kind of type.
>> 
>> You just showed Marko a few posts back, that
>> A generator is a special case of an iterator.
>> And you wrote the iterator with 'class'.
>> And from python 2.2(?) classes are types.
> 
> Yes, but iterators aren't *classes*, they are instances.
> 
> 
>> So I dont know what "comp science theoretic perspective" you are
>> describing...
> 
> http://en.wikipedia.org/wiki/Generator_(computer_programming)
> 
> "A generator is very similar to a function that returns an array, in that
> a generator has parameters, can be called, and generates a sequence of
> values. However, instead of building an array containing all the values
> and returning them all at once, a generator yields the values one at a
> time, which requires less memory and allows the caller to get started
> processing the first few values immediately. In short, a generator looks
> like a function but behaves like an iterator."

Oops, itchy trigger finger... the next paragraph is even more important:

"Generators can be implemented in terms of more expressive control flow
constructs, such as coroutines or first-class continuations.[2] Generators,
also known as semicoroutines,[3] are a special case of (and weaker than)
coroutines, in that they always yield control back to the caller (when
passing a value back), rather than specifying a coroutine to jump to; see
comparison of coroutines with generators."



-- 
Steven




More information about the Python-list mailing list