Douglas Alan wrote:
Steve Holden <[EMAIL PROTECTED]> writes:


Guido has generally observed a parsimony about the introduction of
features such as the one you suggest into Python, and in particular
he is reluctant to add new keywords - even in cases like decorators
that cried out for a keyword rather than the ugly "@" syntax.


In this case, that is great, since I'd much prefer

yield *gen1(arg)

If you do write a PEP, try to get genexp syntax supported by the yield keyword.

That is, the following currently triggers a syntax error:
  def f():
    yield x for x in gen1(arg)

I wouldn't mind seeing it successively yield the values returned by gen1() instead. To my mind that better conveys what's going on than putting the yield statement inside the for loop (it should also provide the opportunity to optimise the next() calls by temporarily swapping the outer generator's frame for the inner generator's frame, and swapping them back only when the inner generator is exhausted)

That syntax error I mentioned makes it backwards compatible, too (existing code must have parentheses around the genexp, which will not by altered if the yield keyword gains a native genexp syntax).

If anyone thinks that this would result in a couple of parentheses making too much difference, consider this:

Py> [x for x in []]
[]
Py> [(x for x in [])]
[<generator object at 0x009E6698>]

Cheers,
Nick.

--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
            http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to