5 ms·
AFAIU Python's closure have been incomplete for a long time. I think they've become true, complete closures after the addition of the nonlocal keyword on 3.0 P
by koide 14y ago
AFAIU Python's closure have been incomplete for a long time. I think they've become true, complete closures after the addition of the nonlocal keyword on 3.0
Please correct me if I'm mistaken. This all comes from a cursory research on the subject.
- klibertp 14y agoIn short, in your opinion, Python has no "complete" closures because you cannot bind a new value to the name from enclosing lexical scope from within a nested scope. I disagree.
- effn 14y agoThis is not possible in Haskell either. You never hear people claiming Haskell doesn't support closures.
- klibertp 14y agoWhich is why I disagree with claims that Python doesn't support them either. It does, of course; we could argue if Python supports "complete" closures, but we won't, because we know better than to use meaningless terms in discussion, right?
- koide 14y agoIn any case it's not been the case in a while, so I stand corrected. Although being able to write on the closed over variable is a neat feature to have, I would argue that feature does make a difference. Whether you call that complete or read-write or however you want to.
- btilly 14y agoTo my eyes they always were true and complete, but you had to play the minor trick of using mutable data to get them. Here is an example of what I mean that has worked forever. def outer (): counter = [0] def inner (): counter[0] += 1 return counter[0] return inner