On Jun 26, 2019, at 15:46, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
Yes, but it's pretty universal across languages with name-binding semantics for assignment (Lisp, Ruby, Javascript etc.) that assigning to a local name doesn't invoke any magic.
I don’t think that’s quite true. Many languages with name-binding semantics simply don’t invoke any magic for any assignments. Among those that do, I don’t think there’s anything universal about allowing it on some scopes but not local. For example, in Lisp, if you replace the setf macro, that replaces local symbol sets just as much as closure, global, and dynamic sets, and even non-symbol sets like to generalized-variables. The fact that Python’s namespaces are object-oriented, and Python makes it very easy to replace or hook class instance namespaces, a bit harder to replace or hook global namespaces, and very hard to replace or hook local namespaces, is probably specific to Python. And think about this: If you had code involving “x = 2” that stopped working when you moved it from local to a module init function to the top level of the module because it was no longer doing anything that could be construed as binding x, would you think “Something is broken”, or “That’s ok, x isn’t local, so I wasn’t expecting assignment to mean binding”? (Code that actually does something fancy with namespaces, your expectations on moving it might be different, of course—but in that case, you’re already thinking about the namespace semantics, so you’re prepared for that.)