[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lightweight function syntax (again) Re: [ANN] Lua 5.2.0 (alpha-rc2) now available
- From: Nilson <nilson.brazil@...>
- Date: Sun, 21 Nov 2010 23:46:23 -0200
Another possible syntax:
For return (single or multiple)
@(a,b; a+b) <=> function(a,b) return a+b end
@(a,b; a+b,a-b) <=> function(a,b) return a+b,a-b end
For execution of a single statement
@(a,b) statement
Perhaps some of these options were mentioned before.
PROs
- more compact in case of multiple return
- different syntax for return expression and for single statement.
- By creating clear boundaries for expression, improves understanding
- Only one new symbol.
CONs
- Extra char in case of single return
- The semicolon has poor visibility (*)
To avoid (*) we could replace the ';' by a new token like '|' or '=>'
@(a,b | a+b,a) <=> function(a,b) return a+b,a end
Or replace it by an already known token like '/'
@(a,b / a+b,a) <=> function(a,b) return a+b,a end
IMO it is a good idea to avoid to use the colon as separator because
Lua extensions may use it to implement type systems. The same is true
for the equal symbol that could be used to implement default
arguments.
--
Nilson