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