lua-users home
lua-l archive

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

On Thu, Jul 11, 2019 at 11:16 PM Egor Skriptunoff <> wrote:

   with white-list-of-names do
>      ....
>   end
This statement makes all names from the outer scope (with exception of white-listed names) invisible in the inner block.

This might solve the long-standing problem with globals.

To avoid introducing the new keyword, and to make things a little less verbose in typical use cases, we could consider a syntax like 

[a. b, c]

that introduces a white list of names, which can appear anywhere a new block (of Lua's grammar) begins, for example:

do [a. b, c]

function(x, y, z) [a. b, c]

if x < y then [a. b, c]
else [a. b, c]

I have chosen square brackets because such a syntax would not be valid in previous versions of Lua, there are certainly other syntactical options to the same effect.

The names thus introduced in the beginning of a block are effective in the entire block, and the effect is otherwise identical with that of Egor's proposal.

Note that every Lua chunk is a block, so [...] in the beginning of a chunk would also work, with the obvious implications on the behaviour of global variables.