Sidenote: the idea I posed is actually borrowed from a language i used to use, Visual Foxpro, where it was implemented using the 'with' keyword.On 5/2/2016 5:28 AM, Franklin? Lee wrote:
On Sun, May 1, 2016 at 4:27 PM, Robert van Geel <firstname.lastname@example.org> wrote:
First of all I'm new to this. I tried figuring out if some inquiry like mineWould the following solve your usecase? Explicit naming:
below already was posted but I couldn't find it, frankly partly because I
don't know what to look for, I'm not sure if there's a name for this idea.
I'm not convinced my idea below is solid so apologies if it's naïve but I
figured to post it anyway.
It has to do with the possibility to fold typical opcodes pairs by
introducing a language construct.
The idea is to be able to write this code:
myobject.d = 1
.d = 1
with myobject import a,b,c,d:
d = 1
Alternatively, putting the object at the end (like in gen expressions):
with a,b,c,d from myobject:
d = 1
* Should this add additional scope?
* Descriptors and `__getattr__`-only attributes: Do you get the
attribute at the start of the block, or do you call `__getattr__`
* That `d = 1` is Pythonically odd if it works as in the original example.
Your proposal has the need to duplicate all variables, so instead of multiple times typing "self." you have to type them double in the line using "with" so it's shorter but not optimally short. Also if you want the accompanying faster opcodes that means you have to put 4 variables on the stack straight away for fast access, instead of one.
To answer you questions:
- No it would not add scope, it's just a combination of syntactical sugar combined with faster opcodes.
- The attributes are not grabbed at the beginning of the block, instead internally in memory there's a 'grabbed object' stack that can be accessed directly without the LOAD_FAST opcode
- Your fourth remarks refers to your non-dotted code. I think the ".d = 1" statement feels pythonic but again maybe because I was so used to the syntax in the VFP language
Python-ideas mailing list
Code of Conduct: http://python.org/psf/codeofconduct/