Next | Functional Programming in Perl | 16 |
def mkcounter(a): def f(): a = a + 1 print a return f
UnboundLocalError: local variable 'a' referenced before assignment
So they tell you to do this:
def mkcounter(a): def f(a=a): a = a + 1 print a return f
But now it doesn't close
You can get closures, sort of
But the closed-over values are read-only
Closures aren't important.
--Guido van Rossum
Next | Copyright 2005 M. J. Dominus |