TopchetoEU
unread,May 28, 2026, 2:11:22 PMMay 28Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to lu...@googlegroups.com
Hello list,
Lua allows calls with table and string literals to omit the call parens, which enables some very elegant and concise DSL-styled syntax. I have been experimenting with extending that idea to function literals, too. This is the core of the syntax:
called_function begin
body_of_function_literal
end
I chose to introduce `begin` as a keyword, as opposed to using the existing `function` keyword, as syntax like this:
print("Hello, world")
function test() end
Would be difficult to parse (not impossible, but would require a look ahead, which would complicate needlessly the parser for such a small feature).
I'm not terribly attached to the `begin` keyword, and I even fear that it could break existing code, as `begin` could be a common variable/field name, so I'm open to suggestions.
Otherwise, I think this would make DSLs much cleaner in some cases, where you need to pass functions, instead of tables. For example, a testing framework could declare its cases like this:
describe "My example test" begin
it "Should be true" begin
assert.truthy(true)
end
end
I have attached a patch file, so you can experiment with it. Note that I haven't spent much time testing it, but nothing *should* break, as it changes about 15 LoC.
Comments and criticism are welcome.