45 ms·
Go managed to use <- still..
by thomasahle 7y ago
Go managed to use <- still..
- jerf 7y agoBeing "valid syntax in other contexts" is language dependent. Go works by taking <- as an operator at a higher priority than the alternative parse, if indeed the "alternative parse" is even possible in the grammar (I'm not checking for a HN post); if you start with https://play.golang.org/p/S_XOiKdyj1A https://play.golang.org/p/S_XOiKdyj1A and remove the space after the less-than symbol and hit run, you'll see it no longer compiles properly. So <- only has one interpretation in Go. By contrast: $ python Python 2.7.15+ ... >>> x = -3 >>> if x<-2: ... print("Hello world") ... Hello world <- appears in a perfectly valid context now that Python parses, in what happens to be the very place that is under discussion, so changing x<-2 to be "set x to 2" would be a non-backwards compatible change in Python.
- pmoriarty 7y agoFor a language that's infamous for its strictness in regards to whitespace, I'm surprised "x<-2" is allowed. Why not just require whitespace around every operator?
- memetichazard 7y agoPython isn't that strict about whitespace? It's just using indents to delineate blocks and newlines implicitly terminate statements (unless you have an unclosed brace). Anywhere else, you can add as much whitespace as you want.
- NieDzejkob 7y agoIt's not strictness with regards to whitespace, it's just using indentation to delimit blocks. The rest is less strict than C, not requiring spaces between numbers and keywords: print(1if 2else 3) is valid Pythonese.