generator/coroutine terminology

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Mar 15 04:37:23 EDT 2015


Rustom Mody wrote:

> On Saturday, March 14, 2015 at 11:34:27 AM UTC+5:30, Steven D'Aprano
> wrote:
>> 
>> A generator (function) may be a function which returns an iterator,...
> 
> I find "generator-function" misleading in the same way that "pineapple"
> misleadingly suggests "apple that grows on pines"

You would be wrong. There's nothing objectionable or misleading
about "generator-function" meaning a function which returns generators.
English is very flexible like that, and compound nouns can be used in many
different ways:

* a greenhouse is not a house that happens to be green;

* a mushroom is not a room where people mush;

* a butterfly is not a fly made of butter;

* a swimming pool is not a pool which swims;

* but a flying squirrel is a squirrel which (almost) flies.

Where a compound noun is made of two nouns, the "important" one can appear
either at the beginning or the end:

* a printer cartridge is a type of cartridge, not a type of printer;

* but an attorney general is a type of attorney, not a type of general.


So there is nothing unusual about "generator-function" being a type of
function.


> A builtin function is a function in the builtin (or builtins -- can never
> remember) module A pure function is function that does not assign or
> mutate non-locals A Steven-function is a function that presumably Steven
> wrote
> 
> However a "generator function" is a weird sort of function (at best).
> Not regarding it as a function is IMO more reasonable.

But it is a function.

You can regard it as a kind of yoghurt, if you like, but it isn't one.


py> def g():
...     yield 1
...
py> from inspect import isfunction
py> isfunction(g)
True



-- 
Steven




More information about the Python-list mailing list