lua-users home
lua-l archive

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


You may want to do that, but your code will be an horror with those pseudo "scope labels".

And the syntax you propose cannot work, as it is ambiguous (you use quoted strings in places where it could start an _expression_ statement. Do you want to repeat the nightmare of semicolons at end of statements ?

So, "end" is not equivalent to "local", just use "local" instead to hide explicit variables, and do not allow "unhiding" specific variables from outer scopes (it would be a very bad practive in my opinion): if you use "end" it terminates the current closure of the function or all "local" or for variables that fall out of scope (and cannot be "resumed in scope" after it). Scopes are necessarily recursively embedded and must never overlap partially (scopes can only overlap entirely, or not at all; each "local" statement starts an embedded scope which fully overlaps the previous scope, until the "end" of function closure or "end" of block).Scopes must form a perfect hierarchic tree with no shared subranches.





Le sam. 29 juin 2019 à 21:29, Soni "They/Them" L. <fakedme@gmail.com> a écrit :


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.