lua-users home
lua-l archive

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


2014-06-04 16:48 GMT+02:00 Axel Kittenberger <axkibe@gmail.com>:

> Lua accepts since ever (as far I know) trailing commas in table definitions.
>
> And this is good, since like most people experience sooner or later, when
> doing multilined stuff taking care of the last element is kinda a hassle.
>
> However, I never understood, why trailing commas are not allowed in function
> calls.
>
> Reasons are the same, sometimes a function call spawns several lines. This
> happens for me especially with functions taking variable length arguments
> like print() or write()
>
> For example:
>
> print(
>     'this is a string',
>     'another string',
>     'yet another string', -- note the comma here
> )
>
> I don't see any ambiguity added by this, or is there?

More generally, "lexical void" inside an argument list could mean nil.
That is something that I (when in a bikeshedding mood) have sometimes
missed, with some library functions where I use seldom use the early
arguments, e.g.

load(source,,,MY_ENV)

But now, in your example, I don't suppose you want

print(
     'this is a string',
     'another string',
     'yet another string', -- note the comma here
)

to mean

print('this is a string', 'another string', 'yet another string', nil )

or would you?