lua-users home
lua-l archive

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

2011/2/11 Roberto Ierusalimschy <>
> > var there can lead to some confusion:
> >
> >  function f(x)[1](y) end
> >
> > because parenthesis are used in multiple ways in Lua (as well as in
> > math): _expression_ grouping, function calls, and function argument
> > lists.
> >
> > is this confusion?
> function foo() end is the semantics sugar of foo = function() end
> so function f(x)[1](y) end is the semantics sugar of f(x)[1] = function(y)
> end

It is confusing for the parser, which will need unlimited look-ahead.
(I think it is confusing for people, too, but I will not argue that.)

 function f(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s).x(a) return a end
 function f(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) return a end

The parser needs to read some 40 tokens before knowning whether the
first 'f' is the name of the new function or a call.

-- Roberto

this is really a problem. Yes you right....