[Python-Dev] PEP 289 - Generator Expressions - Let's Move Forward
Jeremy Hylton
jeremy at alum.mit.edu
Fri Apr 30 16:38:55 EDT 2004
On Fri, 2004-04-30 at 09:30, Barry Warsaw wrote:
> On Fri, 2004-04-30 at 09:07, Armin Rigo wrote:
>
> > This looks (a) cool and (b) a complete hack that nobody should be allowed to
> > do without messing with sys._getframe().
>
> It reminds me a little bit of the dynamic binding in Emacs lisp. As
> incredibly useful as that is sometimes, it's a disgusting hack. :)
The funny thing is that it's the result of a static scoping discipline
rather than dynamic scoping. What's funny about it has more to do with
side-effects that scoping rules. If the x_square function was returned
out of its defining block, there would be no way to rebind x and it
would not be possible to define a variable x local to the caller that
would affect it.
Put another way, it's possible to reason statically about what binding x
will use when x_square() is called. It's the same technique you would
use to write an accumulator generator (that is, a function that returns
accumulator functions). See the appendix of Paul Graham's essay:
http://www.paulgraham.com/icad.html
Jeremy
PS I do owe everyone a PEP on the subject of re-binding.
More information about the Python-Dev
mailing list