Lispy languages like to use this construct for all kinds of purposes. See the appendix at the end of http://paulgraham.com/icad.html for examples.
You can do this in Python too, but it requires a bit more work. Python is asymmetrical here; you can see a variable in an enclosing scope, and if it's a mutable object you can change it, but you cannot reassign the name.
Comments
Lispy languages like to use this construct for all kinds of purposes. See the appendix at the end of http://paulgraham.com/icad.html for examples.
You can do this in Python too, but it requires a bit more work. Python is asymmetrical here; you can see a variable in an enclosing scope, and if it's a mutable object you can change it, but you cannot reassign the name.
Python 3 lets you use the statement 'nonlocal varname' and it will grab it from the outer scope, as well.
Ah, yes. I should have mentioned that I was talking about Python 2.x.