lua-users home
lua-l archive

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


Miles Bader wrote:
> I dunno what you're talking about, but _I'm_ talking about extending
> the current Lua concept of "no parens needed for passing a single
> string/table to a function" concept to work for numbers as well.  
> 
> Such "no parens" invocations bind very tightly to their argument --
> like other unary operators -- so it's pretty clear why the
> _statement_ fun"a".."b" doesn't work.  I don't think it's
> particularly relevant to this question though.   

I think you're right about the fact that syntax-wise passing a single
number constant to a function without parentheses is not more ambiguous
than doing the same with a string or table constructor.

There is however a very minor argument against allowing that. For
whatever reason, there is a *small* risk of losing the space between the
function name and the number argument during source file editing. In all
situations allowed in current syntax this is either not a problem, or it
leads to a early detected syntax error:

- keyword name -> keywordname : syntax error, missing keyword
- name keyword -> namekeyword : syntax error, missing keyword
- name "" -> name"" : not a problem
- name {} -> name{} : not a problem
- name () -> name() : not a problem

However if you allow the call of a function with a single number without
parentheses, the loss of the space is not detectable at parsing, only at
runtime (and not in all cases, because of tolerance to inexistant
globals):

- name 0 -> name0 : valid syntax, lead to a runtime error at best, or
silent behaviour change at worst

This was just my 2 cents :-)