Op 2005-02-09, Nick Coghlan schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> Op 2005-02-08, Nick Coghlan schreef <[EMAIL PROTECTED]>:
>>>The CPython *_FAST opcodes relate to functions' local variables. Behind the 
>>>scenes they are implemented as integer indexing operations into a pre-sized 
>>>C 
>>>array. Operations don't come much faster than that :)
>> 
>> 
>> I don't follow. AFAIR my remark here above was about the STORE opcode.
>> But you seem to react to it as if I am talking about STORE_FAST.
>
> I've been talking about rebinding function local variables all along - which 
> means STORE_FAST. I may not have made that explicit, though.
>
> However, even in the general case, "check it already exists and overwrite it 
> if 
> it does" is going to be slower than "just store it".
>
> The reason is that, if checking for the existence of the name first somehow 
> provides a speed advantage (I still can't see how it could), then the latter 
> case of unconditional storage can check for the names existence *just to get 
> the 
> speed advantage* (the difference being that the name gets bound irrespective 
> of 
> whether it originally existed or not).
>
> Anything that could be used to speed up a rebinding, could most likely be 
> used 
> to speed up a standard binding at the same point in the code. So, while it 
> might 
> be possible to get rebinding code which isn't any slower than a standard 
> binding, it seems practically impossible to do anything to get rebinding code 
> to 
> be *faster*.

Well it seems you have some fair points. I'll just stop here stating
that I would like to have it, even if it proved to be slower. Speed
is not that big a factor in the things I write. I just would like
to ask a question relating semantics. Supose the following code.

x = 42

def f():
  x := 21   #  or x .= 42  I don't remember what you used exactly

f()
print x


What do you feel should happen. I can think of two possibilities.

1) It raises an exception because x is not locally bound.

2) it prints 21.


I think the second option would be the more interesting one as
it would allow to get rid of the global statement and it would
allow for rebinding names within nested scopes.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to