lua-users home
lua-l archive

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

On Tue, Feb 28, 2012 at 4:42 PM, Ross Bencina
<> wrote:
> On 28/02/2012 11:20 PM, Dirk Laurie wrote:
>>> -- sort in the wrong order
>>> >  table.sort(T,|x,y|(x>  y))
>> Easier to write, maybe.  But really easier to read than this?
>> down = function(x,y) return x>y end
>> table.sort(T,down)


table.sort(T, function (x,y)
    return x > y

This kind of function with a 3 character body "x>y" is very rare,
optimising language for it isn't sensible.

Its been pointed out before, that using strings and parsing them and
returning a function is a way of providing this
kind of terseness in an environment that requires it:

table.sort(T, lambda[[|x,y|(x>  y)]])
table.sort(T, lambda"|x,y|(x>  y)")
table.sort(T, L"|x,y|(x>  y)")

A bit of a pain, but if you have so many uses of these tiny
expressions you are dying for a lambda, maybe not too much.


p.s. For what it's worth, I wish "function" was "def", and blocks
returned their last value, but so it goes.