I don’t think your example depicts the ambiguity well.

1. is the correct parsing of the Original1, 2. is the correct parsing of 
Original2 and 3. is not correct for either of those.

Original1
> while a < b (x := c) - 42
Original2
> while a < b(x := c) - 42

1. In this case, it’s obviously this one
> while a < b:
>    (x := c) - 42
2. In here your removed the space, which is not ambiguity, but rather mistype
> Or:
> while a < b(x := c):
>    -42
3. Same as in 2. But also, this is not an option, because if there was no 
indent on the next line, then body exists. So this is incorrect.
> Or:
> while a < b(x := c) - 42:
>    # ???

Having that said, I think readability suffers a lot from not having a colon and 
as you indicated potentially makes parser’s job harder.

Dg.

> On 11 Sep 2023, at 20:11, Celelibi <celel...@gmail.com> wrote:
> 
> 2023-09-05 18:26 UTC+02:00, Dom Grigonis <dom.grigo...@gmail.com 
> <mailto:dom.grigo...@gmail.com>>:
>> I like the idea of eliminating it if it was possible. This is one of my most
>> common syntax errors (although mostly after function signature) and I am not
>> C/C++ programmer. I am not sure about the core technical issues, but
>> readability of code, such as:
>> a = 1
>> while a < 5: a += 1
>> , would suffer:
>> a = 1
>> while a < 5 a += 1
>> So IMO, it does improve readability in certain cases.
>> 
>> Although, removing colon does sound like an idea worth thinking about. I
>> might even dare to suggest disallowing body statement on the same line, but
>> can’t do that for backwards compatibility ofc...
>> 
>> So my point is, if anyone is going to give a thought about this, please add
>> function signature to the list.
>> 
> 
> I just want to mention that without colons, one-liners could become ambiguous:
> while a < b (x := c) - 42
> 
> Is it:
> while a < b:
>    (x := c) - 42
> 
> Or:
> while a < b(x := c):
>    -42
> 
> Or:
> while a < b(x := c) - 42:
>    # ???
> 
> If anything, the colon would become optional but would definitely
> remain in the grammar. Kinda like the semi-colon, only used in
> one-liners.
> 
> When teaching python I noticed the usual uselessness of the colon
> regarding the correct parsing of correctly indented code.
> But I've never seen it as a burden and rarely if ever forgot one. It
> also allows code editors to be very simple: you see a line ending with
> a colon, you indent the next line. The keyword at the begining of the
> line doesn't matter.
> 
> Best regards,
> Celelibi
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org 
> <mailto:python-ideas@python.org>
> To unsubscribe send an email to python-ideas-le...@python.org 
> <mailto:python-ideas-le...@python.org>
> https://mail.python.org/mailman3/lists/python-ideas.python.org/ 
> <https://mail.python.org/mailman3/lists/python-ideas.python.org/>
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/message/UL3FSZWUKOVUASIPM46IPQIQPJ7GEV7Q/
>  
> <https://mail.python.org/archives/list/python-ideas@python.org/message/UL3FSZWUKOVUASIPM46IPQIQPJ7GEV7Q/>
> Code of Conduct: http://python.org/psf/codeofconduct/ 
> <http://python.org/psf/codeofconduct/>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JQGUO6WQ4Y6H4CYNRG7W6AORWKA2TCAE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to