PEP 255: Simple Generators
Just van Rossum
just at letterror.com
Fri Jun 29 02:45:18 EDT 2001
Glyph Lefkowitz wrote:
> My point is that 'yield' is a keyword, and that new keywords are bad.
> Although there has been a Pronouncement on this :) I still disagree with
> it; it would not require a keyword addition if creating a generator were
> something like
>
> import generator
>
> def _genfunc():
> for i in range(100):
> generator.yield(i)
>
> gen = generator.create(_genfunc)
>
> But again, given that there's been a pronouncement, this is just
> rearranging the deck chairs on the titanic, so I'll be quiet now :).
Originally I agreed completely with you, even before the PEP: I wrote a
co-routine module for stackless that had a very similar interface. Why
introduce a new keyword what you can do with calling syntax? (In my
view, generators were (or actually, in a way still are) just a specific
*usage* of co-routines.)
But. When I first saw an example usage of Neils generators I very quickly
changed my mind: the fact that yield is a keyword makes it possible to
make generator instantiation implicit, making generators much more
convenient and natural to use. Imagine that everywhere you can now write
for x in g():
...
you'd have to write
for x in generator.create(g):
...
That's a whole lot of unneeded cruft...
> but-I-still-can't-entirely-forgive-guido-for-print>>-and-lambda-ly y'rs,
Oh, when he added lambda he was still young, so that's easy to forgive
<wink>, but I agree with you regarding print>>: there's no Python feature
I hate more...
Just
More information about the Python-list
mailing list