[Python-ideas] PEP on yield-from: throw example
greg.ewing at canterbury.ac.nz
Wed Feb 18 21:04:48 CET 2009
Bruce Frederiksen wrote:
> 1. The double use of send/throw and the yield expression for
> simultaneous input and output to/from the generator; rather than
> separating input and output as two different constructs. Sending
> one value in does not always correspond to getting one value out.
You might not be interested in sending or receiving
a value every time, but you do have to suspend the
generator each time you want to send and/or receive
Currently, there is only one way to suspend a
generator, which for historical reasons is called
'yield'. Each time you use it, you have the opportunity
to send a value, and an opportunity to receive a
value, but you don't have to use both of these (or
either of them) if you don't want to.
What you seem to be proposing is having two aliases
for 'yield', one of which only sends and the other
only receives. Is that right? If so, I don't see
much point in it other than making code read
> * I'm thinking here of a pair of cooperating pipe objects,
> read and write,
Pipes are different in an important way -- they
have queueing. Writes to one end don't have to
interleave perfectly with reads at the other.
But generators aren't like that -- there is no
buffer to hold sent/yielded values until the
other end is ready for them.
Or are you suggesting that there should be such
buffering? I would say that's a higher-level facility
that should be provided by library code using
yield, or something like it, as a primitive.
More information about the Python-ideas