Why we will use obj$func() often

Mark Hahn mark at prothon.org
Fri Apr 23 16:50:24 EDT 2004


"Mel Wilson" <mwilson at the-wire.com> wrote in message
news:ulXiAls/KH1K089yn at the-wire.com...

> It can, if you spell '&' differently:
>
> def getfunc():
>     def count (n=[0]):
>         n[0] += 1
>         print n[0]
>     return count
>
> c = getfunc()
> c()
> c()
> c()

True.  A bit inelegant, but then so is &.

Would you trade the "mutable integer" and "count(n=[0])" kludges for a
solution like &count ?  Does anyone agree with me that a "closure variable
prefix" is more explicit and readable?

Let's seperate the aesthetic issues of using "Perl-like" symbols from the
"closure variable prefix" functionality for a moment.  I'd like feedback on
both issues, but try to keep them seperate.





More information about the Python-list mailing list