Quote:
That is as confusing as hell even "with" the semicolon, at least to anyone that rationally assumes that () is *supposed* to designate parameters ...
There is an interesting discussion on this point, on this page:
http://www.wowace.com/wiki/Coding_Tips
One of the points made there, is that this can be a function call:
("foo bar"):sub(3, 5) == "o b"
This is because strings have an implied metatable (the string table), and thus that expression is really the same as:
string.sub("foo bar", 3, 5) == "o b"
The important point is, that using that construct, which the syntax of the language supports for a function call, means a function call can start with brackets.
Now whilst most people won't code like that, when language implementors sit down and write a language parser, they have to make it unambiguously support everything in the language specification, even if some things won't be written by humans.
Many languages have a "statement terminator" syntax, so that the parser can know when one statement ends, and another starts. For example:
- C / C++ / PHP - statements are terminated by the ";" character
- Cobol - statements are terminated at the end of the line, unless there is a "continuation character" in column 6 of the next punched card.
- Visual Basic - statements are terminated at the end of the line, unless the line ends with the "_" character. Also, you can use ":" to separate multiple statements on one line.
Now Lua does not require a specific terminator character, however in occasional places it requires a semicolon to disambiguate.
I don't think I have ever found this to be a problem except when I occassionally put a function call on one line, and start its arguments on the next (usually because the line is very long). eg.
a = b + c + d + f
(x, y, z)
This above code gives the error message. All you have to do is make sure the function name and its opening bracket are on the same line, either:
a = b + c + d + f (
x, y, z)
or
a = b + c + d +
f (x, y, z)
or
a = b + c + d + f (x, y, z)
I think this one idiosyncracy is not too bad, as it lets you have multi-line statements, without either needing "_" at the end of each line (as in VB) or a semicolon at the end of every statement everywhere (as in C). |