bad recursion, still works
mdsherry at gmail.com
mdsherry at gmail.com
Thu Jul 17 13:30:48 EDT 2008
On Jul 17, 8:27 am, Jeff <jeffo... at gmail.com> wrote:
> Thanks, that made things very clear. I like that technique for adding
> memoization via the parameter. That is clever. It would be nice if
> there were a way to have multiple functions close over a shared local
> variable in Python, like let-binding in lisp.
Is this something like what you're looking for?
>>> def functionmaker():
... shared = []
... def addnumber():
... shared.append(3)
... return shared
... def addletter():
... shared.append('f')
... return shared
... return addnumber, addletter
...
>>> addnumber, addletter = functionmaker()
>>> addnumber()
[3]
>>> addletter()
[3, 'f']
More information about the Python-list
mailing list