lua-users home
lua-l archive

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


On Fri, Oct 2, 2009 at 11:04 PM, Luiz Henrique de Figueiredo wrote:
>> In a recent thread [1], I brought up the concept of a 'begin' keyword
>> that can be used to create anonymous, argument-less functions.
>
> Here a token filter in C that does that. Enjoy.

...except for adding the parenthesis, which likely requires keeping
track of the nesting levels to know when to inject the terminal ")" :

  prefixexp begin ..... end --> prefixexp ( function() ..... end )
  prefixexp : Name begin ..... end --> prefixexp : Name ( function() ..... end )

This is related to the "do patch" [2], which is one solution to the
short anonymous functions problem [2].  However, using "do" for your
keyword leads to an ambiguity if you also allow omission of
parenthesis: "f () do end" could be one statement or two.

[1] http://lua-users.org/wiki/LuaPowerPatches
[2] http://lua-users.org/wiki/ShortAnonymousFunctions