Rule of order for dot operators?

Ron Adam ron3200 at gmail.com
Mon May 18 22:43:49 EDT 2015



On 05/18/2015 09:32 PM, Rustom Mody wrote:
>> >In particular, each .foo() need not return a string - it might return anything,
>> >and the following .bah() will work on that anything.
> For an arbitrary binary operator ◼
> x ◼ y ◼ z
> can group as
> (x◼y)◼z
> or
> x◼(y◼z)
>
> One could (conceivably) apply the same rule to x.y.z
> Except that x.(y.z) is a bit hard to give a meaning to!!

Yes.

Having just implementing something similar for nested scopes, it turns out 
it can't be operators because if it was, then the names y and z would be 
resolved in the wrong scope.

          y = "m"
          z = "n"
          a = x . y . z

Which of course wouldn't do what we want.

          a = x . "m" . "n"

And most likely this would give an error.


The name-part after the dot is evaluated in the next inner scope.  y is 
resolved in x's scope, and z is resolved in y's scope.

Which is why you can implement objects with closures, but you need to delay 
name resolution to do that.   Which is what the "." does.


Pythons attribute lookup is a bit more complex than this of course.

      https://docs.python.org/3.4/howto/descriptor.html


Cheers,
    Ron








More information about the Python-list mailing list