Python becoming less Lisp-like

Antoon Pardon apardon at forel.vub.ac.be
Fri Mar 18 07:18:38 EST 2005


Op 2005-03-16, Jeff Shannon schreef <jeffshannon at gmail.com>:
> Bruno Desthuilliers wrote:
>
>> A few examples:
> [...]
>> - to get the length of a sequence, you use len(seq) instead of seq.len()
>> - to call objects attributes by name, you use [get|set]attr(obj, name 
>> [,value]) instead of obj.[get|set]attr(name [,value])
>
> These are both very consistent applications of a more functional style 
> of programming, rather than the pure object-oriented style you seem to 
> desire.  It's not that Python is inconsistent; it's that Python is 
> consistently blending multiple paradigms in a way that uses the best 
> features of each and (mostly) avoids the worst pitfalls of each.
>
>> - 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.  Doing as you suggest would be far 
> *less* consistent, and would create a special case for class/instance 
> lookups where there is none now.
>

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

-- 
Antoon Pardon



More information about the Python-list mailing list