lua-users home
lua-l archive

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


Let's talk about non-lexical lexical scopings. That is, the ability to undefine variables.

That ability is itself lexically scoped, ofc.

E.g.

a = 2
local a = 1
do
  forget a
  print(a) assert(a == 2)
end
print(a) assert(a == 1)

This also applies to upvalues:

do
  a = 0
  local a, a, a = 1, 2, 3
  function f()
    assert(a == 3)
    forget a
    assert(a == 2)
    do
      forget a
      assert(a == 1)
      forget a
      assert(a == 0)
    end
    assert(a == 2)
  end
  assert(a == 3)
  f()
  assert(a == 3)
end
f()

So, non-lexical scoping doesn't forget the *values*, but the variables/bindings.

I think this sounds neat. What do you think?

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.