[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Syntactic sugar for function parameters
- From: Rici Lake <lua@...>
- Date: Mon, 5 Feb 2007 08:47:07 -0500
On 5-Feb-07, at 2:07 AM, Ivan-Assen Ivanov wrote:
About empty (): without it, how would you make the difference between
the
function itself ( e.g. to pass it as a parameter to a higher-order
function), and the application of that function?
I'm not talking about the empty () at the end of a application without
parameters, but the empty () after the function keyword when an
function without parameters is defined:
foobar = function() frob() end
If you could leave out the () in that, it would turn into:
foobar = function frob() end
but
function frob() end
is a statement defining the function frob.
That's not strictly speaking ambiguous, since a statement cannot follow
the symbol '=', but it's very confusing.
Here's a real ambiguity, though. The following is a valid Lua statement:
(a)(b)
The () around the a are unnecessary in this case, but they are legal.
So, now consider:
foobar = function (a) (b) (c) end
If you could leave out () after 'function', then that becomes
ambiguous: is it a function of no arguments whose body is (a)(b)(c), or
is it a function of one argument (a) whose body is (b)(c)