Kristján Valur Jónsson wrote:
> Are you all certain that this mapping from a generator expression to
> a foor loop isn't just a happy coincidence? After all, the generator
> statement is just a generalization of the list comprehension and that
> doesn't map quite so directly.

The mapping of the for and if clauses is identical for both generator
expressions and the various flavours of comprehension. It's only the
outer wrappings (creating a generator/dict/set/list) and the innermost
loop body (yield statement/item assignment/set add/list append) that
differ between the constructs.

As Terry noted, it's even defined that way in the language reference -
the expressions are pure syntactic sugar for the corresponding statements.

While this doesn't often matter in practice (since people tend to switch
to using the statement based versions rather than writing convoluted
multiple clause comprehensions), it's still an important symmetry that
matters greatly to Python VM implementers so any proposed changes need
to take it into account.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to