[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Non-lexical (lexical) scoping
- From: dyngeccetor8 <dyngeccetor8@...>
- Date: Wed, 21 Mar 2018 01:15:59 +0300
On 03/20/2018 02:57 PM, Soni "They/Them" L. wrote:
>
> In Lua, the only use-case I can think of is for accessing shadowed variables in
> a block scope:
>
> function f(a, flag)
> local a = a or {}
> local b = true
> if flag then
> forget a -- temporarily forget the shadowed `a` so we can get to the
> original `a`'s nil/false-ness
> b = not not a -- tobool operator
> end
> -- use the shadowed `a` normally
> end
I think better way is to allow indirect access to lexical scope
variables. Like "_G" but populated with local variables. (And
some awkward name to access outer level, say "__parent".)
So you code example becomes
function f(a, flag)
local a = a or {}
local b = true
if flag then
b = not not _ENV.__parent.a -- tobool operator
end
-- use the shadowed `a` normally
end
I believe this may be implemented but will introduce much more
problems than solve.
-- Martin