lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Reuben Thomas wrote:
> But there's another nicer solution to this: lexical scoping with nested
> functions. This is sort of provided in Lua by upvalues, but because
upvalues
> are frozen they don't work properly. It'd be better if Lua had proper
> closures; then upvalues needn't be frozen, and we could use the full power
> of lexical scoping.

and

> It'd be nice to see the current proposals laid out thusly: first, what
would
> local-by-default syntax look like

These are conflicting goals.  Python, when proper lexical scoping was added
to the language, couldn't support rebinding of outer-scoped variables due to
its lack of variable declarations (that is,  local-by-default semantics).
>From the Statically Nested Scopes PEP
(http://python.sourceforge.net/peps/pep-0227.html):

    The only kind of declaration is the global statement, which allows
    programs to be written using mutable global variables.  As a
    consequence, it is not possible to rebind a name defined in an
    enclosing scope.  An assignment operation can only bind a name in
    the current scope or in the global scope.  The lack of
    declarations and the inability to rebind names in enclosing scopes
    are unusual for lexically scoped languages; there is typically a
    mechanism to create name bindings (e.g. lambda and let in Scheme)
    and a mechanism to change the bindings (set! in Scheme).

As a solution to the accidental-assignment-to-global (the only problem I'm
interested in solving), I'm against local-by-default because I want to see
proper lexical scoping with rebinding in Lua someday, and because as a C
programmer I'm comfortable with declaring local variables.

Regards,
-John