Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Being "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 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.


For 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?


It'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.


Python 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: