[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Syntactic Sugar for function??
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 26 Mar 2002 09:27:59 -0300
> What's the Problem? A Bug? Or even intenion?
Neither. It is a syntactic ambiguity. You can write
f(a,b,c).x = function (x,y,z) ... end
However, if you write
function f(a,b,c).x(x,y,z) ... end
the parser cannot tell that "(a,b,c)" is not the formal parameter list
(well, it could when it sees the dot, but then it is too late). So, the
form "function var (...) ... end" must have some restrictions.
In Lua 4.0, "var" can be only a name, name.name, or name:name. In 4.1',
this has been extended to name.name... But "var[exp]" is not accepted.
The meaning of "function var ..." is exactly the same as "var = function
...". So, whenever you cannot use the sugar, use the full syntax.
-- Roberto