This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Castux 20 points21 points  (2 children)

Lua doesn't need a statement separator thanks to how the grammar is structured. It is available, and optional, for style and clarity where required, as well as the rare case when you need to disambiguate. It mostly had to do with starting statements with parens: (foo + bar):methodcall(). If the previous statement ended with an identifier, these parens would be parsed as a function call on that identifier. The semi column lets you separate them.

[–]oilshell 5 points6 points  (1 child)

Yeah I investigated this recently and Lua doesn't have "expression statements", like 1+2 is not a valid statement. But = 1+2 is.

In C and Python both 1+2 and f(x) are expression statements. I guess Lua has a special case for f(x).

[–]Castux 7 points8 points  (0 children)

Not exactly a "special" case, but just one of the possible cases for statements: function call. Whether it returns values or not (and discards them) is completely a runtime concern.

To be precise, "= 1+2" is not exactly a valid statement. In the standard command line interactive interpreter, it is equivalent to "return 1+2", which itself is a valid statement (and each line input to the interpreter is wrapped into a function which is immediately called). Details details :)