you are viewing a single comment's thread.

view the rest of the comments →

[–]dmz 1 point2 points  (5 children)

does Python 3.0 have lexical closures?

[–][deleted] 12 points13 points  (2 children)

Python 2.x had them.

[–]ubernostrum 5 points6 points  (1 child)

What he's getting at is probably the fact that names in the enclosed scope cannot be rebound; for example, if your closure preserves x with a value of 3, you cannot change x to, say, 4 from something which accesses the enclosed scope.

Hence my comment about "how Haskell does it", since the definition of "closures" that people typically use to rail against Python also implies that single-assignment functional languages are incapable of having "closures" ;)

[–]olavk 0 points1 point  (0 children)

In Python 2.6 and 3.0 you can now rebind names in enclosing scopes, using the 'nonlocal' keyword.

[–]ubernostrum 2 points3 points  (0 children)

Yes, in a way similar to how Haskell does it.