lua-users home
lua-l archive

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

(Trying to get back to the topic...)

Again deferring to Scheme, redefinitions act the same as
assignments... So, for example:

    guile> (define x 3)
    guile> (define (f) x)
    guile> (f)
    guile> (define x 5)
    guile> (f)

Here's R5RS again:

  At the top level of a program, a definition

  (define <variable> <expression>)

  has essentially the same effect as the assignment expression

  (set! <variable> <expression>)

  if <variable> is bound. If <variable> is not bound, however, then
  the definition will bind <variable> to a new location before
  performing the assignment, whereas it would be an error to perform a
  set! on an unbound variable.

I think it would be nice for lua to adopt a similar policy for locals,
as has been suggested by others. I'd like:

    local x = 3
    function f() print(x) end
    local x = 5

to print '3, 5' instead of '3, 3'... It seems like this still allows

  local _, _ = f()

idiom to work as expected.


Matt Hellige