On Thu, May 27, 2021 at 01:02:15PM -0700, Brendan Barnwell wrote:

>       You can already do that:
> 
> def merge_shortest(things):
>      len=len
>      ...
> 
>       Yes, it does require a single global lookup on each function call, 
>       but if that's really a bottleneck for you I don't think there's much 
> hope.  
> :-)

It's not so much the single global lookup on each function call as the  
fact that you can't do that at all :-(

UnboundLocalError: local variable 'len' referenced before assignment


[...]
>       Sorry, I was a bit vague there.  What I was envisioning is that you 
> would specify len as a constant at the GLOBAL level, meaning that all 
> functions in the module could always assume it referred to the same 
> thing.  (It's true this might require something different from what was 
> proposed in the other thread about constants.)

Getting actual constants that the interpreter can trust will not change 
is likely to be a much bigger language change than taking advantage of 
existing mechanisms that already exist in functions, with perhaps a 
little extra work, to get per function local static storage.

But even if we did have actual constants, how does that help get static 
*variables*, you know, things that aren't constant but can vary?



-- 
Steve
_______________________________________________
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/IDDOIZTBSW3LSMGOLXCUQCKIQ2R6J42H/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to