lua-users home
lua-l archive

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


On Mon, May 26, 2014 at 10:53 AM, Xavier Wang <weasley.wx@gmail.com> wrote:
> What about just like C++'s lambda syntax?
>
> table.sort(t, _1 > _2)

That's what I did in Penlight:

http://stevedonovan.github.io/Penlight/api/topics/07-functional.md.html#Placeholder_Expressions

Although there are limitations - you can't express and/or as operators.

PL also does 'string lambdas', but in the explicit '|x,y| x > y' form
(string lambdas are very efficient to memoize).  There's also a short
form with a single argument '_', Scala-like.  Just about all PL
functions can accept string lambdas:

> l = List{10,20,5,2,6}
> = l:filter '_ > 10'
{20}