Python becoming less Lisp-like

Antoon Pardon apardon at forel.vub.ac.be
Mon Mar 21 02:56:13 EST 2005


Op 2005-03-18, Jeff Shannon schreef <jeffshannon at gmail.com>:
> Antoon Pardon wrote:
>> Op 2005-03-16, Jeff Shannon schreef <jeffshannon at gmail.com>:
>> 
>>>Bruno Desthuilliers wrote:
>>>
>>>>- if x is a class attribute of class A and a is an instance of A, 
>>>>a.x=anyvalue create a new instance attribute x instead of modifying A.x
>>>
>>>This is very consistent with the way that binding a name in any scope 
>>>will shadow any bindings of that name in "higher" scopes.  It is the 
>>>same principle by which one is able to use the same name for a 
>>>function-local variable that is used for a global variable, without 
>>>destroying that global variable.  [...]
>> 
>> Not entirely. The equivallent is imposible in function scope.
>> If function scope would work exactly equivallent as the
>> above the following should work 
>> 
>>     a = 42
>>     def f():
>>       a = a + 1
>>       print a
>>     print a
>> 
>> And the result should be:
>> 
>> 43
>> 42
>> 
>
> I'd still say that the name binding rules are very consistent.  The 
> name lookup rules are a little different (as they *should* be for 
> class/instance attributes),

Why should they? 

> and that's why there's a different net 
> effect (UnboundLocalError) as shown in your example.  I'd say, 
> however, that if there's a special case here it's with the 
> function-local variables, not the class/instance attributes.

Which is the special case and which is the normal case is not
that important here. The fact is that they behave different,
so you can't claim it is very consistent.

I'm getting the impression that 'consistent' just means:
that is how python works, on this newsgroup.

> It's the 
> optimizations to the function-local namespace which prevent 
> transparent re-binding of global names.  And given that the 
> function-local namespace is by far the most heavily used, and the 
> relative utility (and wisdom) of using globals in this way, this is a 
> case where the benefit of the special case is well worth the cost of 
> its slight inconsistency.

I find it odd that you start by saying you still find them very
consistent and here state there is a slight inconsistency.

It seems we mean different things with "very consistent"

-- 
Antoon Pardon



More information about the Python-list mailing list