[Python-Dev] closure semantics
Samuele Pedroni
pedronis at bluewin.ch
Wed Oct 22 13:32:56 EDT 2003
At 14:27 09.12.2000 -0500, Jeremy Hylton wrote:
> > But all this is moot unless someone comes up with a way to spell this
> > that doesn't require a new keyword or change the meaning of 'global x'
> > even if there's an x at an intermediate scope (i.e. you can't change
> > 'global x' to mean "search for the next outer scope that defines x").
> >
> > And we still have to answer Alex's complaint that newbies misinterpret
> > the word 'global'.
>
>I'm not averse to introducing a new keyword, which would address both
>concerns. yield was introduced with apparently little problem, so it seems
>possible to add a keyword without causing too much disruption.
>
>If we decide we must stick with global, then it's very hard to address
>Alex's concern about global being a confusing word choice <wink>.
why exactly do we want write access to outer scopes?
for completeness, to avoid the overhead of introducing a class here and there,
to facilitate people using Scheme textbooks with Python?
so far I have not been missing it,
I don't find:
def accgen(n):
def acc(i):
global n in accgen
n += i
return n
return acc
particulary more compelling than:
class accgen:
def __init__(self, n):
self.n = n
def __call__(self, i):
self.n += i
return self.n
I'm not asking in order to polemize, I just would like to see the rationale
spelled out.
regards.
More information about the Python-Dev
mailing list