lua-users home
lua-l archive

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


On 2/5/07, Ivan-Assen Ivanov <ivanassen@gmail.com> wrote:
Hello,

throughout our code we frequently use the following construct:

foobar( function() ..... end )

where the anonymous function body is often very small.

Leaving cancer of the semicolon concerns aside, maybe this is just
begging some form of syntactic sugar, similar to

foobar "string" as an equivalent for foobar("string")
or
foobar { foo = "bar" } as an equivalent for foobar( { foo = "bar" } )

What would you suggest as a possible syntax? It has to be
implementable with token filters, and simple enough to fit with the
overall syntax of the language.
E.g.

foobar function ... end ?

Why do we need the empty () in normal Lua anyway? I guess they are
needed to disambiguate in some situation, but I can't think of it...

Best regards,
Assen

I'm currently thinking of using
 begin ...... end
syntax for anonymous parameterless functions, and
 something begin ..... end
as a syntactic sugar for
 something(begin .... end) -> something(function() ..... end)

I also consider existing do..end patch for anonymous functions.. but
not yet sure if it will introduce some ambiguity in the syntax

--
Kirill Zakharenko/Кирилл Захаренко (earwin@gmail.com)
Home / Mobile: +7 (495) 683-567-4 / +7 (903) 5-888-423
ICQ: 104465785