lua-users home
lua-l archive

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


Why everything so complicated?

How about simply this

lambda(x) x == 2

no end, no return, no statements before return, if you want statements
use function() syntax. The lambda goes until end of statement, if you
want to write more in the line use a ';' to separate it like other
statements. A lambda function is also by itself terminated by a ','.
If you need something like 'if', use something like 'select' when in
function-coding-style-mode.

return lambda() x, y   ==is==> return function() return x end, y

if you want to return multiple value, use brackets:

return lambda()(x, y)  ==is==> return function() return x, y end

I think its a good compromise, not gibberish, still shorter. One can
argue if its worth the new keyword. Might not be, less worth than a
'continue' keyword anyway :-)

2010/11/25 Pierre-Yves Gérardy <pygy79@gmail.com>:
> A sentence got lost somewhere...
>
>>    foo = {}
>>    function bar()
>>        foo.baz = do[] return "Something" end
>>    end
>>
>>    bar()
>>    foo.baz() --> an error should be raised.
>
> "bar" could be compiled as
>
>>    function bar()
>>        local _R = true
>>
>>        foo.baz = do[]
>>            if _R
>>            then return "Whatever"
>>            else error()  end
>>        end
>>
>>        _R = false
>>        -- <----------- return goes here.
>>    end
>
> -- Pierre-Yves
>