[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why Lua allow an extra comma after the last element of a table?
- From: steve donovan <steve.j.donovan@...>
- Date: Sun, 10 Mar 2013 16:53:11 +0200
On Sun, Mar 10, 2013 at 12:35 PM, Rena <hyperhacker@gmail.com> wrote:
> Why not? I find it very convenient.
Best possible answer ;)
If you ever play with Go, be prepared for _compulsory_ extra comma!
m := map[string]int {
"alpha":1,
"beta",2,
}
It's needed because otherwise the semi-colon inserter gets over-eager.
(Not needed for single-line map literals)
Lua really has a gorgeously simple syntax.
Any further convenience comes at the cost of complexity. For instance,
in Moonscript, the commas are optional because newlines are
significant:
myfun {
'one'
'two','three'
'four'
}
This is very nice for DSLs.. But significant-newlines means that one
can't just extend a statement over several lines, as you can _mostly_
do in Lua. You can pass multiple arguments to a function, but then
the first argument must be on the first line, and you _do_ need commas
(and no final comma!)
print 'one',
'two',
'three'
I do like MS, but there is a lot more to remember.
steve d.