lua-users home
lua-l archive

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


metalua (a lua compiler which supports full macros and code manipulation at the AST level) offers by default "|foo, bar| xxx" as an alternative syntax for "function(foo, bar) return xxx end"; it proves quite nice to use: readable, compact and currying-friendly. I'd guess that you could implement it with token filters, if you're able to figure aout the end of an arbitrary _expression_. Or you could hack something like adding mandatory parentheses around the lambda.

I've also experimented with shorted syntaxes for multiple statements instead of single expressions as aboved, but in the end I felt that it wasn't worth it. However, you can still use it (it's "do |foo, bar| stat1; stat2;...statn end"  in the currently available version IIRC), or define whatever suits you.

http://metalua.luaforge.net (a 0.3 version is due for Real Soon Now, as soon as documentation will be up to date).

About empty (): without it, how would you make the difference between the function itself ( e.g. to pass it as a parameter to a higher-order function), and the application of that function?