lua-users home
lua-l archive

Re: Function definitions in table constructors

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


Miles Bader wrote:
>
> Mark Hamburg <mhamburg@adobe.com> writes:
> >> so table-constructor methods have a lightweight syntax.
> >
> > But to really make it pay off one needs some way to also remove the need for
> > a comma after the end.
> 
> Yeah, I've always found the need for "," or ";" inside table
> constructors inside tables annoying... Do things become overly
> ambiguous without them though?
I have that in my Lua dialect and there are some pitfalls but
I never stepped into one. I usually use commas but omit them
when they are annoying, i.e. after function statements.
IMHO, if you can manage the different precedences of + and * you
can handle this, too.
 
Excerpt from http://goron.de/~froese/sol/Diffs2Lua
---snip---
 - Commas and semicolons are optional but may be used to
 avoid ambiguities. There's no semantic difference
 between a comma and a semicolon.
 { a=1 b=2 c=3, d=4; e=5;,; 32 f, (1+2)*3 }
 Be careful when a field is followed by a string constant,
 a table constructor, or a parenthesized or negated
 expression:
 { f "foo" } vs { f, "foo" }
 { {} {} } vs { {}, {} }
 { a=1 (2+3) } vs { a=1, (2+3) }
 { a=1 -2 } vs { a=1, -2 }
 It's recommended to be not too economic with commas ;-)
 - Named functions may be used as rec-fields:
 {
 function foo() .... end
 function bar() .... end
 }
---snip---
Ciao, ET.

AltStyle によって変換されたページ (->オリジナル) /