lua-users home
lua-l archive

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


Bret Victor <bret@ugcs.caltech.edu> 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.

I agree, in general -- I don't dislike punctuation heavy languages like
C, but Lua has a consistent and attractive style of its own.  [Still, in
the middle of an expression, I think a punctuation-oriented lambda
syntax isn't out of place, even in Lua.]

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

That's pretty nice.

How would it work for lambdas with zero arguments (a very common case).
"(in ...)"  would be consistent, but weird.
  
>     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)

Now that's ugly... :-/

Thanks,

-Miles

-- 
Friendless, adj. Having no favors to bestow. Destitute of fortune. Addicted to
utterance of truth and common sense.