On Jun 27, 2019, at 16:18, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
> 
> Andrew Barnert wrote:
>> in Lisp, if you replace the setf macro,
> 
> Okay, maybe Lisp wasn't a good example. In the presence of macros,
> all bets are off. :-( But at least if you haven't redefined the
> universe, local bindings in Lisp behave predictably.

Right, but if you haven’t redefined the universe, global (and dynamic and so 
on) bindings behave predictably too. There’s nothing special about locals that 
makes them untouchable, or even harder to touch, then any other namespace.

And I think that’s more typical among name-binding languages than Python’s 
“locals are special, nobody can touch them”. Python’s behavior seems to be 
mainly a side effect of the fast-locals optimization. (That restrictive side 
effect might well be a good thing for people maintaining 10-year codebases and 
trying to keep them readable, but those are usually not the kind of benefits 
that other language designers steal from Python.)

>> 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 ...
> > would you think “That’s ok, x isn’t
>> local, so I wasn’t expecting assignment to mean binding”?
> 
> I wouldn't think "x isn't local", because it still *is* local
> from the point of view of that piece of code.

That’s  great way to put it.

And that’s why I think if it’s not acceptable to add these books to locals, 
it’s at least questionable behavior for globals (or, conversely, if it is 
acceptable to hook global this way, it should be acceptable to hook locals 
too). There are ways in which locals and global act differently, for good 
reasons—but otherwise, they act as similarly as possible, which is what allows 
you to think of globals as local to global code.



_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/5XKTMXZH23KQTURXS46FCW73ZO4P32XM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to