lua-users home
lua-l archive

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


In 5.1 the manual says that
function name()
end
is equivalent to
name=function()
end

It confused me quite a bit when that didn't hold true in table constructors.
I propose allowing this in a table constructor.

{function name()end}
rather than
{name=function()end}

and possibly even this
{function[anyvalue]()end}
rather than
{[anyvalue]=function()end}

There is no ambiguity, it looks nicer (to me), and it follows the
principle of least surprise, because it follows the rest of the
language.

That would be a simple addition to the language.

Another far off version of the language (Lua 7?) might look like this:
Anything should be allowed in table constructors, including blocks and
flow control, similar to in env do ... end like this:
something={
  if a then b=3
  else b=4
  end
}

And maybe a new keyword 'value' that almost acts as a return
statement, but puts them in the table like {value1,value2,value3} does
a=true
t={if a then value 'hello' end}
print(t[1]) --> hello

Environments and table constructors would be almost identical.

Just a few thoughts.