Op di 31 jul. 2018 20:49 schreef Jonathan Fine <jfine2358@gmail.com>:
David Mertz wrote:

> `spam?.eggs?.cheese?.aardvark` is NOT redundant for
> `spam?.eggs.cheese.aardvark`.  The two expressions simply do different
> things [...]

I agree, assuming ?. is a binary operator. 

It isn't.


Given this, in Python (+
PEP 505) one can write

    tmp = spam ?. eggs
    val1 = tmp ?. cheese ?. aardvark    # For spam?.eggs?.cheese?.aardvark
    val2 = tmp . cheese . aardvark    # For spam?.eggs.cheese.aardvark

Nope, the introduction of the tmp variable changed the semantics. It isn't a "chain" anymore so it breaks shortcutting.

To be honest I didn't get this either until it was pointed out to me 

No special knowledge of PEP 505 is needed. If val1 is always equal to
val2, then the dot and None-dot operators must be the same. From the
assumptions, this is something that can be mathematically proved.

And false.


By the way, there's a widely used programming language in which
    val = a.method()
and
    tmp = a.method
    val = tmp()
are not always equivalent. Can you guess which language it is?

Javascript.
I suppose in the same way as x+2 and x*2 are " not always" equivalent.

Stephan



The answer is in:
https://www.slideshare.net/jonathanfine/javascript-the-easiest-quiz-in-the-world-ever
(question 6: Dot binds).

I'll now go back to following the example of Steve Bower and Raymond
Hettinger, which in my words is to wait until we have proper cover for
the BDFL's vacation.

--
Jonathan
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/