On Tue, Dec 15, 2020 at 01:16:21PM +0300, Paul Sokolovsky wrote:

> You're now just a step away from the "right answer". Will you make it?
> I did.

Sorry Paul, but you didn't.

You fooled yourself by comparing chalk and cheese, and imagining that 
because you can eat cheese (change the order of operation by using 
parens, which is a semantic difference), you can also eat chalk (imagine 
a semantic difference between `obj.method` and `(obj.method)`).

Your mistake was comparing `(obj.method)()` with `a + (b + c)` when you 
should have compared it to `(a + b) + c`. Not every source code 
difference has a semantic difference:

    x = 1
    x=1
    x  =      1
    x = 1 or None
    x = (1)

all mean the same thing. Putting parens around the final (1) changes 
nothing.

Let's get away from using round brackets for function call, because it 
clashes with the use of round brackets for grouping. All we really need 
is a *postfix unary operator*.

    x()  # the brackets are "postfix unary zero-argument function call"

Let's use the factorial operator, "bang" `!` instead.

    obj.attr!

has to be evaluated from left to right under Python's rules. You can't 
apply the factorial operator until you have looked up attr on obj, and 
you cannot lookup attr until you have looked up obj.

So the only possible order of operations is left to right. This is not 
meaningful:

    # attr factorial first, then lookup obj, then the dot lookup
    obj.(attr!)  

but while this is meaningful, the order of operations is unchanged:
    
    # lookup obj first, then dot lookup attr, then factorial
    (obj.attr)!  

Replace the factorial postfix operator with the `()` call operator, and 
the logic remains the same.


-- 
Steve
_______________________________________________
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/MYH6ZCW3RJYEUSTHYXHTLTBX3M72OROV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to