4 ms·
Also, JavaScript.
by xpl 2y ago
Also, JavaScript.
- gary_0 2y agoAnd Kotlin and Swift.
- xigoi 2y agoExcept JavaScript does it wrong.
- trealira 2y agoWhat makes Go's semicolon insertion algorithm different from JavaScript's? They seem similar to me. Isn't it just that the Go compiler requires very strict formatting, which saves you from getting bitten by errors due to unexpected semicolons?
- xigoi 2y agoThe following (contrived) JavaScript code does not work: let x = 5 (function() { console.log(x) })() The equivalent Go code works: package main import "fmt" func main() { x := 5 (func() { fmt.Printf("%d", x) })() }
- trealira 2y agoThanks, that's a good case. Actually, the JavaScript semicolon insertion algorithm [0] seems more complex than I had remembered. I had thought of them as variations on the semicolon insertion in BCPL, but it seems like that's an oversimplification. For reference, these are the BCPL rules: The canonical symbol SEMICOLON is inserted between pairs of items if they appeared on different lines and if the first was from the set of items which may end a command or definition, namely: BREAK RETURN FINISH REPEAT SKET RKET SECTKET NAME STRINGCONST NUMBER TRUE FALSE and the second is from the set of items which may start: a command, namely: TEST FOR IF UNLESS UNTIL WHILE GOTO RESULTIS CASE DEFAULT BREAK RETURN FINISH SECTBRA RBRA VALOF LV RV NAME ... ( ) [ ] § § are used to denote RBRA RKET SBRA SKET SECTBRA and SECTKET. [0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#automatic_semicolon_insertion https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- kazinator 2y agoBourne and POSIX shell: for x in *.txt; do echo $x; done for x in *.txt do echo $x done