generator/coroutine terminology

Rustom Mody rustompmody at gmail.com
Mon Mar 16 22:52:59 EDT 2015


On Monday, March 16, 2015 at 11:50:33 PM UTC+5:30, Mark Lawrence wrote:
> On 16/03/2015 14:37, Rustom Mody wrote:
> > On Monday, March 16, 2015 at 7:57:08 PM UTC+5:30, Mark Lawrence wrote:
> >> On 16/03/2015 14:19, Rustom Mody wrote:
> >>> ======================
> >>> Anyways...
> >>>
> >>> Yes 15 years are past.
> >>> I dont expect the def can be revoked now.
> >>> [As far as I am concerned its a minor wart]
> >>> But the mess around the docs can certainly be cleaned up.
> >>>
> >>
> >> So write the patches to correct the docs, then raise the issue on the
> >> bug tracker to get the patches accepted.  IIRC for doc patches you don't
> >> even have to provide diff files against the rst files, plain text will
> >> do, the core devs will do the rest for you.
> >
> > I would gladly do that if it was a minor correction here and there.
> > But the problem is a bit deeper even though it can be kept mostly¹ in the docs
> > and not modify any syntax/semantics of python.
> >
> > In particular for:
> >
> > def potato(x):
> >    yield x+1
> >
> > tomato = potato(3)
> >
> > what shall we call potato and tomato.
> > I believe this thread clearly shows that the docs are confused and inconsistent.
> > Yet I dont see any consensus on what/how to classify tomato/potato.
> >
> > Function -- trouble on one side
> > Generator -- trouble on another
> > Iterator -- trouble on third
> > etc
> >
> > ¹ Grey areas excepted eg output of help(); inspect module etc
> >
> 
> So the docs are confused and inconsistent but in an open source 
> community it's not *MY* responsibility to deal with it, somebody else can.
> 
> Making mountains out of mole hills is all I see in this entire thread.

Ok... Lets see... What if any agreement is there on this.

To start with basic terminology. Given

> def potato(x):
>    yield x+1
>
> tomato = potato(3)
>
> What shall we call potato and tomato?

Steven suggested that potato can be called 'factory'
Not ideal, but way better than 'generator-function'.
Oscar does not like it.
No better/other suggestions (that we see here).

What next?

Ok Let me throw out a suggestion:
 - potato is a generator
 - tomato is a cursor.
Acceptable?

So much for terminological questions.
When we go from 'simple-generators' to coroutine-generators there seem to be
bigger conceptual problems and implementation-gaffes.
Quite frankly I hardly understand this part.
Here are some questions.

1. Is the name generator appropriate for coroutine-generator?
The wikipedia-link that Steven posted suggests the other-way-round 'is-a'
relation: "a generator is a (semi)coroutine¹"
2. Can we say
   yield-statement ≡ generator
   yield-expression ≡ coroutine
   ?
   What of x = yield y
           x = yield x

  My (vaguest) impression is that 'yield' stops being the meaningful word
  for coroutine -- see footnote from Frederik Lundh in the 2001 thread

> suspend instead of yield, but that's me
--------------------
¹ Non-trivial terminological headache: Is this 'generator' in the old sense or new
sense?



More information about the Python-list mailing list