[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Lua 5.2.0 (alpha-rc2) now available
- From: Nilson <nilson.brazil@...>
- Date: Sat, 20 Nov 2010 11:53:19 -0200
2010/11/20 Pierre-Yves Gérardy <email@example.com>:
> On Friday, November 19, 2010, Petite Abeille <firstname.lastname@example.org> wrote:
>> On Nov 19, 2010, at 11:08 PM, Luiz Henrique de Figueiredo wrote:
>>> can now write
>>> ; (exp)...
>> Ah, excellent, thanks!
> Definitely :-). The only feature in my whishlist still missin in 5.2
> is short lambdas.
> Functions are first class citizens semantics-wise, but not
> syntax-wise, when compared to strings or table IMO.
> At a glance, function calls and anonymous function declarations are
> too similar, making lambda-rich code harder to read than it should be.
> I would love to have the ability to pass functions without parentheses
> like you can do with string and table literals. Finding an appropriate
> candidate (simple, short and unambiguous yet not too ugly) is not
> easy, though. I've submitted such a patch a while ago and have messed
> with a lot of variations sonce then, but I couldn't find an obvious
> My main considerations are:
> a) the token opening the block
> b) the argument list
> c) the return token
> d) the token closing the block
> The easy stuff first: the return token could be "|" as in the current
> power patch, or "=>", which is more meaningful but longer.
> I like "@" as an initial token because it is distinctive. far more
> than a potential "fn" keyword, for example. :(, :[ or :] could also be
> used, but it would overload the meaning of existing symbols.
> The argument list doesn't need delimiters except when there are no arguments.
> @[ a,b => a+b ] would work, but how would one represent an empty list?
> Perhaps by using the empty statement?
> function make_counter()
> local a = 0
> return @[; a=a+1; => a ]
> If we chose to have an argument list delimiter, Do we balance the
> block opening token
> @[a,b| =>a+b ] -- use a pipe
> @[a,b; => a+b ] -- make an empty statement mandatory at the
> beginning of the block?
> @ a, b [=> a+b]
> @[a,b] => a+b ]
> @[a,b] => a+b end
> Regarding the code modifications, it is a bit more complicated to
> restrict the short return statement to the short functions, but I
> think it would be better to confine it there.
> My favourite syntax so far is
> @[ a,b => a+b ]
> @[; dostuff() ]
> I would love to hear the opinion of Roberto and Luiz on this topic.
> Kind regards,
> -- Pierre-Yves
Would you like of
a) @(parameters) exp
b) @(parameters) single-statement
a) function (parameters) return exp end ?
b) function (parameters) single-statement end ?
@(a,b) do --statements end
Considering the later example, a function definition could be seen as
a syntactic sugar of
"function (...) end " <=> "@(...) do .... end"