lua-users home
lua-l archive

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


> IIUC you’re saying that ‘foo nil’ is grammatically ambiguous… how so?

How do you expect the following to be processed:

a = foo nil
foo nil

It's going to be processed the same way as `a = foo nil foo nil`,
which is the same as `a = foo(nil)(foo)(nil)`, which is likely far
from what you intended. This is the same issue that exists today with:
`a = foo(nil)<CRLF>(foo)(nil)`, but it affects fewer cases comparing
to what you're proposing.

I think another argument for *not* doing it is that in the current
case there are pairs of delimiters for function calls (which requires
2 typos to make a mistake), which in the case you're proposing you're
one character away from making something semantically invalid that
will only fail at run-time.

Paul.

On Thu, May 25, 2023 at 8:15 AM David Sicilia <dpsicilia@gmail.com> wrote:
>
> IIUC you’re saying that ‘foo nil’ is grammatically ambiguous… how so?
>
> On Thu, May 25, 2023 at 9:58 AM Paul Ducklin <pducklin@outlook.com> wrote:
>>
>> 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