Python syntax in Lisp and Scheme

Alex Martelli aleax at aleax.it
Sat Oct 4 04:45:41 EDT 2003


Grzegorz Chrupala wrote:
   ...
> class foo:
>                         def __init__(self, n):
>                             self.n = n
>                         def __call__(self, i):
>                             self.n += i
>                             return self.n

some might prefer:

def foo(n):
    tot = [n]
    def acc(i):
        tot[0] += i
        return tot[0]
    return acc

which is roughly equivalent.  It's true that most Pythonistas prefer to
use class instances, rather than closures, in order to group together
some state and some behavior, and the language favours that; and Python
separates expressions and statements quite firmly, so one just can't
increment-and-return in one stroke, nor define-and-return-function ditto.
But I don't see how these issues spell "awkwardness" in this case.


Alex





More information about the Python-list mailing list