lua-users home
lua-l archive

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




On 2017-04-27 02:33 PM, Egor Skriptunoff wrote:
On Thu, Apr 27, 2017 at 5:43 PM, Soni L. <fakedme@gmail.com <mailto:fakedme@gmail.com>> wrote:

    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.


The following looks nice:
local swap = function(a,b) = b,a
local swap = (function(a,b) = b), a

But what does the following nested lambda
local x = function(a,b) = function() = a, b
mean:
local x = function(a,b) = (function() = a, b)
or
local x = function(a,b) = (function() = a), b
?

You need to use select() if you want multiple return values. It's a single end-of-list-expr.

(OT: Sorry for accidentally replying wrong. Some thunderbird update changed the behaviour of the "reply" button so instead of defaulting to reply-to-list I need to actually click the reply-to-list button, which I'm not used to doing.)

--
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.