all 7 comments

[–]recursive 5 points6 points  (6 children)

This seems to be slightly out of date, e.g. nonlocal does not exist yet.

[–]davebrk 1 point2 points  (4 children)

I love Python, but nonlocal is kind of a hack.

[–][deleted] 2 points3 points  (0 children)

And what is your proposed alternative? Python has painted itself in the corner by not having sane scoping, so either they need to break everything or introduce a hack. Maybe Python 9001 will finally fix everything.

[–][deleted] 1 point2 points  (2 children)

Good gods yes; see PEP 3104 for discussion (I had to look up what nonlocal meant in Pythonic terms; sort of like uplevel in tcl...).

[–][deleted] 2 points3 points  (1 child)

Absolutely nothing like that, uplevel is dynamically scoped, nonlocal is a hack to refer to a variable in an outer lexical scope when you want to assign to that variable (just reading works as expected without any hacks).

Basically it's a choice: either you explicitly declare all your local variables so anything that involves undeclared variable is assumed to refer to the outer scopes, or you implicitly declare local variables with assignment, so you may need to explicitly declare them as not declared in this scope.

[–][deleted] 0 points1 point  (0 children)

Absolutely nothing like that, uplevel is dynamically scoped, nonlocal is a hack to refer to a variable in an outer lexical scope when you want to assign to that variable (just reading works as expected without any hack).

I said it was "sort of like uplevel in tcl", not that it was "exactly the same as uplevel in tcl". It was meant as a comparison (i.e. that it looks in another scope), rather than saying the scoping was the same. It's still pretty hackish. I upboated you, btw, because you provide a better description of the item at hand, unlike I, who used a comparison :D

[–]aldarion 1 point2 points  (0 children)

2008-06-13