News for hackers. Stuff that matters.
Re:The Zimbu programming language, by vim author Bram Moolenaar by eru on Thursday October 22, 2009 @04:47AM (#896402)
As far as I know Python has true lexical scoping for functions, if not for blocks. (They used to have very limited scoping ages ago.)

What do you mean?

Re:The Zimbu programming language, by vim author Bram Moolenaar by silentbicycle on Thursday October 22, 2009 @06:51PM (#897881)
In Python 2.6:

    def acc(x):
        foo = x
        def closures_are_broken():
            foo += 1
            return foo
        return closures_are_broken
    
    
    def acc2(x):
        foo = [x]
        def closure_with_workaround():
            foo[0] += 1
            return foo[0]
        return closure_with_workaround
The former is an error ("UnboundLocalError: local variable 'foo' referenced before assignment"), the latter is a workaround by manually boxing the variable in a list. I'm not sure why that works, but it's rather ugly.

The same, in Lua:

    function acc(x)
       local foo = x
       return function()
                 foo = foo + 1
                 return foo
              end
    end
Re:The Zimbu programming language, by vim author Bram Moolenaar by eru on Friday October 23, 2009 @09:15AM (#898672)
Oh, yes. You are mutating variables. You shouldn't do that anyway in a functional setting.

Python's syntax forces the language to guess whether you want to make a new variable or use the variable of the same name from the outer scope. The heuristic they have, says that if you assign something to the variable, you get a new one by default. You can declare

  global x
before to assign to the variable in the outerscope.