lua-users home
lua-l archive

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

Miles Bader <miles.bader <at>> writes:

>          |a, b|(a + b)
>             =>  function (a, b) return (a + b) end
>          |a|{ print (a) }
>             =>  function (a) print (a) end

I thing I like about Lua syntax is that punctuation is kept minimal, 
and words are used (in, do, end) when that's how you would read the 
code out loud.

A Lua-like syntax for closures might mimic Lua's for-loop syntax:

    for a,b in some(expression) do  ... end

Here's an expression closure:

    local add = (a,b in a + b)
 => local add = function (a,b) return a + b end
    local sum = fold(t, 0, (a,b in a + b))
 => local sum = fold(t, 0, function (a,b) return a + b end)

Here's a statement block closure:

    local happyprint = x in do print(x .. "!") end
 => local happyprint = function (x) print(x .. "!") end

    table.foreach(t, x in do print(x .. "!") end)
 => table.foreach(t, function (x) print(x .. "!") end)

I'm not perfectly happy with either of these, but it's a start, maybe.