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?

Yes, The manual *defines* the meaning of a comprehension in terms of the corresponding nested statements.

"The comprehension consists of a single expression followed by at least one for clause and zero or more for or if clauses. In this case, the elements of the new container are those that would be produced by considering each of the for or if clauses a block, nesting from left to right, and evaluating the expression to produce an element each time the innermost block is reached." (3.0 doc)

It was originally defined as exactly equivalent (with empty list initialization added). The only intended change of the slightly softer newer version is that the target name bindings do not escape the scope of the comprehension.

The proposed change would BREAK the definition and intent of what a comprehension means.

> After all, the generator statement is just a generalization
> of the list comprehension

I would call it a variation. Syntactically, a generator statement is a comprehension with parentheses instead of square brackets or curly braces.

tjr

_______________________________________________
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