lua-users home
lua-l archive

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


Philippe:

On Sun, May 24, 2020 at 2:23 PM Philippe Verdy <verdyp@gmail.com> wrote:
>
> Oh, and did I say that I hate the notation forcing us to use [] for keys in table constructors ?
> -  {[10]=11}, why not just  {10=11} ???
> -  {['a string']='something'}, why not just {'a string'='something') ?

> The notation using [] is just needed when keys are expressions with arbitrary types, but it should never be needed if keys are static strings or numbers.

No, it is not. In your example above, how do you differentiate betwee
"1".."0" and 5+5 ( both written as 10 )

> But in fact, given that "=" is reserved for assignment instructions, the [] is never needed syntaxically: in table constructors, the "=" replaces the assignment, but it is in fact a true assignement (of a key), so this shouldbe valid as well:
> -  {sin(x) = 1}, i.e. the same as today's {[sin(x)] = 1}

And how do you parse "{a=1,b=2}", as ["a"]=1,["b"]=2 or as ["a=1,b"]=2
or, if you allow the same extension in values, ["a"]="1,b=2" ?

You could come up with elaborate rules for all of that, but it is
normally better to limit to simple specs, like unbracketed keys can
only be identifiers and always parsed as strings.

By the way, your "true assignment" will force you to write {"a"=1} for
the current {a=1}, i fact unquoted names would be interpreted as vars.

FOS