
FWIW, I like ?? It is short and distinctive. There is prior art in this spelling in c#. It requires no new keyword, nor does it give new meaning to an existing one. I understand why ?[ needs to be spelled using only a single ?, but I am afraid it will be used infrequently, and people will accidentally write a??[x] which is legal but different. I found the example code in the PEP using ?. and ?[ hard to read. ?? and ??= are compelling, though. One more question: what does this do? del x x ??= 42 Stephan Op do 19 jul. 2018 15:00 schreef Judah Levy <judah.j.levy@gmail.com>:
On Thu, Jul 19, 2018 at 8:47 AM Rhodri James <rhodri@kynesim.co.uk> wrote:
On 19/07/18 09:33, Antoine Pitrou wrote:
There is a use case I sympathize with: the argument-is-None case. For that I would suggest a simpler form: "A else B" which would evaluate to A if A is not None, otherwise to B (parentheses may be mandatory).
So e.g. one of the examples would read:
def insort_right(a, x, lo=0, hi=None): # ... hi = hi else len(a) # ...
Much as I would like a keyword, "else" is the wrong one. It implies we are dealing with truthiness, which we aren't, and lays a subtle semantic trap as a consequence.
If anyone can think of a good word for "if it isn't None, otherwise", I'd be all for it :-)
-- Rhodri James *-* Kynesim Ltd _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
I think that it may look better with the order switched and the word unless, as in
def insort_right(a, x, lo=0 hi=None): # ... hi = len(a) unless hi # ...
Unfortunately, this does maybe feel more like checking for truthiness than non-Null value _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/