lua-users home
lua-l archive

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


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