3 ms·
> These are three instructions to the computer, with semicolons in between. Now, what about that red semicolon at the end? If the language is Java, C, or C++, t
by User23 5y ago
> These are three instructions to the computer, with semicolons in between. Now, what about that red
semicolon at the end? If the language is Java, C, or C++, that semicolon is required. If it’s Perl, Pascal, or
PL/I, that semicolon is forbidden. Not exactly easy to learn
In my mind the logical way to view this is that semantically some languages use ";" as a statement terminator:
S1; S2;
This is executing S1 followed by S2. In this case ";" is purely syntactic, it has no semantic meaning beyond telling the interpreter/compiler where a statement's procedure text ends.
The other way is using ";" as a statement compositor:
S1; S2
This is defining a single compound statement whose semantics are the same as executing S1 followed by S2. In this case ";" has semantic meaning.
Of course, practically speaking most languages kind of just conflate the two. For example the first way could have syntactic sugar allowing the final statement terminator to be elided. Similarly, the second way could have a trailing ";" and it could just mean compose on a NoOp. And when it comes to actually executing the code both will probably run very similar processes. But I personally find the latter conceptual framework more aesthetically pleasing.
It looks like the Snap developers share my view that semantics is way more interesting than syntax.