[Python-ideas] PEP 505 (None coalescing operators) thoughts

Andrew Barnert abarnert at yahoo.com
Mon Sep 28 18:46:15 CEST 2015


On Sep 28, 2015, at 09:40, Donald Stufft <donald at stufft.io> wrote:
> 
> could use two words!
> 
> result = spam or else eggs

Unless you change the tokenizer to understand "or else" as a special case, or add another level of lookahead to the parser, how do you handle "spam if eggs or else cheese else aardvark" and vice-versa? It does make the meaning less confusing to a human, but it makes understanding how the compiler parses that meaning harder to understand to a human.

>> On September 28, 2015 at 12:38:21 PM, Steven D'Aprano (steve at pearwood.info) wrote:
>>> On Mon, Sep 28, 2015 at 06:11:45PM +0200, Sven R. Kunze wrote:
>>> 
>>> That sums it all up for me as well, though I would rather use "else"
>>> instead of "or?" (see punctuation-heavy).
>> 
>> `else` is ambiguous. Consider:
>> 
>> result = spam if eggs else cheese else aardvark
>> 
>> could be interpreted three ways:
>> 
>> result = (spam if eggs else cheese) else aardvark
>> result = spam if (eggs else cheese) else aardvark
>> result = spam if eggs else (cheese else aardvark)
>> 
>> Whichever precedence you pick, some people will get it wrong and it will
>> silently do the wrong thing and lead to hard-to-diagnose bugs. Using
>> "else" for this will be a bug-magnet.
>> 
>> 
>> 
>> --
>> Steve
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
> 
> -----------------
> Donald Stufft
> PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA
> 
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list