lua-users home
lua-l archive

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


On 05/06/2019 23.13, John Erling Blad wrote:
I wonder if the following could be changed

   args ::=  ‘(’ [explist] ‘)’ | tableconstructor | LiteralString

It is in the doc [1] and is somewhat limiting. It would be better if
it included all literal values, and I can't see how this could be a
problem, but perhaps there are some other reason why this is
disallowed?

[1] https://www.lua.org/manual/5.3/manual.html#8

Lua doesn't do static typing, which means that in order to somewhat
reliably detect typos at compile time, it needs a larger amount of
syntactically invalid programs.

There's already the problem that `local x, y z = 1, 2, 3` results in a
global variable `z = 1` and empty locals `x, y`.  (I once spent far too
much time searching for this one, still painfully remembered…)

Permitting any literals as unparenthesized arguments would mean that
`local x, y, z = foo 23, 42` would be interpreted as a function call.
(Same for argument lists of function calls, multiple return values,
table constructors…)

I suspect that the trade-off between space/time saved on getting rid of
the parentheses vs. extra time spent searching typos that are now run
time instead of compile time errors is not in favor of this change.

-- nobody