namespace for generator expressions

I'm happy to see progress on the generator expressions implementation, but I think the specification of namespaces, which is just a sketch, might be simplified. The details begin by saying that a generator expression is equivalent to creating an anonymous generator function and calling it. Good! I think that will match an experienced programmer's intuition about how it works. This simple model seems to be at odds with the later suggestion that all free variables are bound using default argument values. An anonymous generator function would just have free variables, bound by the usual rules. The PEP suggests that a binding using default argument values is what you want. It's hard to argue one way or another without compelling examples, but I think this is a case of special cases aren't special enough to break the rules. Are there any other cases where an expression is evaluated using non-current bindings? The only near comparison is with list comprehensions, which aren't lazy, but do follow the normal rules. Any code that depends on what binding is used for a free variable is going to be obscure. The example in the PEP is contrived, of course, but I can't imagine any code where it wouldn't be easy to achieve the desired result by using a new variable that is not rebound after the generator expression is defined. Do you think there is any significant gain in expressiveness? The PEP says that no examples have been found where it would be better to use the normal rule. On the other hand, it doesn't show any examples where's it's obviously better to use the proposed rule. Another angle on this concern is the extra complexity it adds to the language reference and to other explanations of the language's name binding model (thinking of course materials, books, etc). The new rules adds non-trivial complexity to those rules, because we've got to distinguish two kinds of code blocks that follow different rules for free variables. Jeremy

I'm happy to see progress on the generator expressions implementation, but I think the specification of namespaces, which is just a sketch, might be simplified.
Ouch! Where were you when this PEP was discussed on python-dev? I was originally strongly in your camp, but Tim and several others convinced me that in every single case where a generator expression has a free variable, you want early binding, not late. --Guido van Rossum (home page: http://www.python.org/~guido/)

On Mon, 2004-01-26 at 10:51, Guido van Rossum wrote:
I'm happy to see progress on the generator expressions implementation, but I think the specification of namespaces, which is just a sketch, might be simplified.
Ouch! Where were you when this PEP was discussed on python-dev? I was originally strongly in your camp, but Tim and several others convinced me that in every single case where a generator expression has a free variable, you want early binding, not late.
I guess I was busy with other things. I'm sorry I missed the discussion, but if it was at all substantial, the PEP didn't do a good job of capturing it. Jeremy
participants (2)
-
Guido van Rossum
-
Jeremy Hylton