lua-users home
lua-l archive

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

How about
   [ x : x > 3 ]
   [ x, y : x+y, compute_something_else(x,y) ]

Syntax (reusing Lua syntax terms):
   '['  parlist ':'  explist ']'

This form would syntactic sugar for
   function(parlist) return explist end

- keep it simple: no statement, no block, just an expression.(if
function is more complex, just use regular 'function ... end' syntax)
- a closing token which makes it easy to have multiple return values
- balanced openning/closing tokens, which makes it easy to see the
anonymous function boundaries within any reasonable text editor
- no keyword that may be unfamiliar to some (lambda)
- no '\' which may be hard to type on some keyboards, ... and which
may introduce some confusion with hex escape chars (eg. using a local
variable named 'n': the form \n(n*n) needs some escaping to be loaded
with loadstring...)

What do you think?

On Fri, Nov 26, 2010 at 1:09 AM, steve donovan:
>> How about simply this
>> lambda(x) x == 2
> Fine, but then you started to make it complicated ;)  If there are
> actual statements in an anonymous function, then the existing syntax
> is fine as it is.
> I read this as 'lambda' <arglist> <expr>, with the operator 'lambda'
> <arglist> having the highest precedence.
> Not sure in fact whether multiple return values should even be allowed
> in this case .... that is, how one would interpret this?
> lambda() (10,20)
> The syntax and semantics should be as simple as possible,and then
> there are less ugly edge cases.