lua-users home
lua-l archive

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


Then perhaps the issue would better be solved with new keywords rather than trying to add modifiers to “local”. For clarity, I would much prefer to write:

do
  local a,b,c
  autoclose e,f,g
  const t = 2*math.pi
  ...
end

to declare what are essentially three very different sorts of local object, rather than denote (using that rather clumsy angle-bracket syntax) that they are all local variables with slightly different flavours.

As many have said, the idea of a “constant variable” is kind of weird. And if a to-be-closed variable is such a different sort of beast to a regular local variable that it needs different compile time opcodes, then it doesn’t seem weird to have a unique keyword to declare it. In fact, it feels weird to use the same keyword “local” to declare them all, especially the idea of a “local constant variable”. 

(The idea of “constant variables” sounds very strange indeed - as strange as saying that local variables that are initialised to a fixed value, as in the code “local flag = true”, should be called “variable constants” :-).


On 14 Jun 2019, at 13:02, Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:

On Fri, Jun 14, 2019 at 2:27 PM Paul Ducklin wrote:

The <toclose> flag for a variable should simply be set automatically at runtime when the setmetatable() function is called for the variable.



To-be-closed variables should be visible at compile-time because they affect VM instructions in the compiled bytecode.
For example, tailcall is not allowed in the scope of to-be-closed variable.