News for hackers. Stuff that matters.
Re:Just why did people start using Python anyway? by anamax on Thursday October 09, 2008 @11:48AM (#327927)
Argh - I can't get the formatting to work.

def makeAdder2(x):

    v = [x,]
    def inc(y):
        v[0] += y
   	return v[0]
    return inc
works just fine in all pythons with closures (2.0 and above?)

def makeAdder2(x):

    def inc(y, v=[x,]):
        v[0] += y
   	return v[0]
    return inc
Also works and provides a mechanism for resetting the state.
Re:Just why did people start using Python anyway? by silentbicycle on Thursday October 09, 2008 @01:03PM (#328017)
Interesting. So keeping a reference to a list with the value works, but the value directly doesn't? Thanks for the note.

Good to know it's possible, though I'd rather it handle closures / lexical scoping directly.