lua-users home
lua-l archive

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

So, out of all syntax proposals for lambas, I'm surpised nobody thought of this beauty.

You see, we have `local x = function(a,b,c) return thing end` syntax. BUT:

1. It's a syntax error to use `function(a,b,c) =thing end`, even if the REPL accepts `=` as an alias for `return`.
2. Do we need `end` if we restrict it to a single expression?

Combine these 2, and the simplest solution seems to be:

local x = function(a,b,c) = thing

AND we can still get multiple returns:

local x = function(a,b,c) = select(1,a,b,c)
print(x(1, 2, 3)) --> 1, 2, 3

The idea is, function(a,b,c) starts a plain old function. If the next token is a =, this has to be a lambda. Otherwise it has to be a function.

There's no ambiguity here since the proposed syntax is currently a syntax error. It also looks very much like Lua.

Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.