lua-users home
lua-l archive

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


On Mon, Aug 23, 2010 at 5:41 PM, RJ Russell <russellsprouts2@gmail.com> wrote:
> 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.

If it's important to me, I prefer to just use "function table.method()
end", outside the constructor. The dropped "in some_env do ... end"
statement is probably closest to what you're asking for, though.

> 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
> }

Looks like Ruby to me.

~Jonathan