lua-users home
lua-l archive

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


>Perhaps removing the ability for 
>table definitions to allow a final 
>comma is the thing that needs to 
>be changed to make things consistent?

As the history of Lua explains, the purpose of making the comma a terminator and not a separator in table initialisers was to simplify the code you’d use to generate tables (Lua started out as a data-processing language for which generated tables - think JSON today -  were an important form of input.

The comma rule therefore avoided the (annoyingly complex) “last line is a special special case” test you would otherwise need, thus reducing the chance of incorrect input.

Not sure that you would ever want to generate long function invocation statements… and if you were planning on passing an arbitrary set of inputs to a function, you would almost certainly choose to do it using the f{} form, with named and not positional parameters, thus improving readability, avoiding the need to insert nil for missing parameters, and not needing to worry about the order of the keys in the table initialiser.

These recent  “let’s try and find new places to lose round brackets and add trailing commas” seems very much like a pair hammers looking for nails to me.

I have very often given thanks for the trailing comma in table initialisers but have never wanted, let alone needed, to write f(a,b,).

I have never felt like writing f 2 instead of f(2), either, given the ubiquity of the notation f(), for which f{} or f”” or f[[]] are at least reasonable lexical substitutions.