lua-users home
lua-l archive

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




On 2019-06-29 4:18 p.m., Philippe Verdy wrote:
Le sam. 29 juin 2019 à 21:11, Soni "They/Them" L. <fakedme@gmail.com <mailto:fakedme@gmail.com>> a écrit :
>
> There's nothing unsafe about "unset" because it's exactly equivalent to
> renaming your (local) variables.


If you unset a variable to get the effect of hiding it completely and get access to the homonymous variable from an outer scope, and then modifying it, it is unsafe.

This does not happen when you redeclare a local variable that makes the previous one out of scope and unreachable. As well when you set that variable to nil this does not alow the homonymous variable from a previous scope to become accessible.

Really, "unset" is not needed and dangerous. Just use "local" instead.

"unset" is equivalent to "end". it just happens to, itself, be lexically scoped.

if each block (scope) could have a name and you could overlap them however you like:

do 'foo'
  local x = 1
  if a then 'bar'
    end 'foo'
    local z = 2
    x = z
    do 'foo'
  end 'bar'
  assert(x==1)
end 'foo'

"unset" is no more dangerous than using different names.