lua-users home
lua-l archive

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


Visually, round brackets delimiting function call arguments can be omitted when there is exactly one argument and *if it already has a natural-looking pair of delimiters around it anyway*, thus allowing {} instead of the lumpier-looking ({}), or [[]] instead of ([[]]).

But

foo nil 

just looks like a mistake, and probably would be.

In parsing terms, this syntactic sugar (or “missing sugar”) is also grammatically unambiguous to deal with, which foo nil is not.

I’d rather see the grammar changed to enforce the round brackets in every case than see the parser hacked to allow them to be left out when they are visually and syntactically purposeful.

foo nil, indeed!!!?!!!!

Next you will want to allow foo instead of foo(), because if you can have foo nil, surely you must allow foo with no explicit args at all.





> On 25 May 2023, at 13:46, David Sicilia <dpsicilia@gmail.com> wrote:
> 
> Why does  Lua allow some but not all of these?
> 
> function foo(…) end
> 
> foo ‘hello’ — ok
> foo {}  — ok
> foo 5  — not ok
> foo nil  — not ok
> 
> Would be nice if we could allow all of them.
> David