question about generators
tim.one at comcast.net
Thu Aug 22 04:21:08 CEST 2002
> There is no reason to believe that
> yield every [(x,) for x in s]
> won't iterate through all of s, build up a list, then yield its elements.
OTOH, there's every reason to believe that's exactly what it would do
> And the first idea that comes to mind, namely to allow the "yield every"
> syntax to incorporate list comprehensions directly
> yield every (x,) for x in s
> or even
> yield (x,) for x in s
> strikes me as too clever. Oh well.
It's part of why generators will always be more natural in Icon, I think.
"suspend expr" in Icon doesn't have to worry about which pieces of expr are
and aren't generators, because all Icon expressions are generators. Python
needs to draw a distinction. There's a vaguely similar gotcha in Icon,
where, e.g., if L is an Icon list, newbies can get confused that
does one suspend of the list as a whole instead of suspending each list
element in turn. The latter needs to be spelled
instead, to turn "L" from an expression that generates itself into an
expression that generates its containees. If Guido wanted to integrate
generators more deeply into Python, we could likewise say
to do what the proposed
yield every s
to do what the hypothetical
yield (x,) for x in s
does. I'm viewing "!" as a tightly-binding prefix operator there, markihg
"the generator" part(s!) of an expression. Indeed, we could dispense with
"yield" in these cases too. Double indeed, the more convenient we made
this, the more likely Guido would be to reject it both instantly and
More information about the Python-list