Why we will use obj$func() often

Mark Hahn mark at prothon.org
Fri Apr 23 14:21:16 EDT 2004


"David MacQuigg" <dmq at gain.com> wrote

> I would take this as constructive criticism, not an ad-hominem attack.

Yes, I admitted I was mistaken.  I was upset when I read the message and I
misread it as a slur.

> Adding syntax or making changes just because it allows you to do
> something that can't be done in Python is not good. We have to look at
> *use cases* for these features and compare them to a well-written
> Python equivalent.  Then, we can see if the benefit is worth the extra
> syntax.  We spend far to much time debating syntax without a clear
> benefit in mind.  Show us a nice closure.

The benefits of closures are well known.  I'll give you the canonical
example, but I'm sure textbooks can give you many more (by the way, Python
cannot do this):

# tested example
def getFunc():
    counter = 0
    def count():
            &counter += 1
            print &counter
    return count

c = getFunc()
c()     # prints 1
c()     # prints 2
c()     # prints 3






More information about the Python-list mailing list