lua-users home
lua-l archive

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


On Wed, Jun 12, 2019 at 2:46 PM Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> Right now, my only complain with the <toclose> is the term "close" that I
> found a bit vague and over-loaded (conceptually).

Suggestions are welcome.

If we must stick with modifiers of local, 'scoped" seems better to me.

I would also like to request comments for another modifier: alias', to be used as follows:

local <alias> foo = bar

where bar can be any Lua _expression_. Following this declaration, any use of foo would be (logically) replaced with bar. To clarify, the difference with

local foo = bar

is that in the latter foo captures the value of bar when the local statement executes, so it can neither refer to the value of bar after that point, nor be used to modify the value of bar (if the _expression_ is modifiable). To illustrate the latter point, consider:

local bar = 1
local foo = bar
foo = 2
-- the value of bar is still 1

But

local bar = 1
local <alias> foo = bar
foo = 2
-- the value of bar is now 2

Another example is 

local <alias> foo = bar.baz
foo = 42
-- the value of bar.baz is now 42

In principle, 'alias' and 'const' could be combined, so that we could say something like:

local <alias, const> for = "" -- combination syntax TBD

Again the difference with local foo = bar.baz is that the former foo references the value of bar.baz even if it changes after the declaration of foo.

Cheers,
V.