5 Apr 2011
A very interesting post from AndrĂ© Pang about some issues he came across with lamdas and closures in Python. Well, interesting to me because I’m playing with Lisp and Python at the moment.
Some links from his blog, in case the original post ever disappears:
- the question and responses on stackoverflow
- an example of the perils of Python’s scoping rules with for/while/if
- Wikipedia – differences in semantics of closures
A nice snippet of code to remind me of the issues:
def callback(msg): print msg funcList=[] for m in ('do', 're', 'mi'): # funcList.append(lambda: callback(m)) funcList.append(lambda m=m: callback(m)) for f in funcList: f()comments powered by Disqus