lua-users home
lua-l archive

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


Here is an example usage:

    table.sort( t, << a, b | a.field < b.field >> )

Or:

    table.sort( t, | a, b | a.field < b.field )

Versus:

    table.sort( t, function( a, b ) return a.field < b.field end )

Admittedly, that would probably be better handled by a more sophisticated
sorting function that allowed for projecting values and sorting on the
projected values, but while table.sort takes the form that it does, making
it easy to use pays dividends.

The syntactically shortened code isn't that much shorter, but percentage
wise for the expression it has a much higher signal-to-noise ratio.

Of course, there's also:

    table.sort( t, compare_fields( 'field' ) )

But now you need to remember all of the library functions such as
compare_fields.

Mark