[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: upvalues actually are values?
- From: Elias Barrionovo <elias.tandel@...>
- Date: Tue, 23 Oct 2012 19:48:57 -0200
On Tue, Oct 23, 2012 at 7:19 PM, Coda Highland <chighland@gmail.com> wrote:
> Then you would be wrong. :P You can still consider it a closure if it
> COPIES the scope instead of REFERENCES it. The ability to modify the
> state of a closure after it's created isn't a requirement to the
> definition of a closure.
As a matter of fact, Python does not allow one to modify the closure state:
#closure.py
def new_inc()
i =0
def inc(n):
i += n
return i
return inc
inc1 = new_inc()
print(inc1(2))
Traceback (most recent call last):
File "closure.py", line 9, in <module>
print(inc1(1))
File "closure.py", line 4, in inc
i += n
UnboundLocalError: local variable 'i' referenced before assignment
--
NI!