Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90823

Re: Rule of order for dot operators?

From Ron Adam <ron3200@gmail.com>
Subject Re: Rule of order for dot operators?
Date 2015-05-18 22:43 -0400
References <55579886.3010001@cdreimer.com> <mailman.118.1431989304.17265.python-list@python.org> <fabab250-d7a5-49f4-a9ef-359bd003a607@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.120.1432003441.17265.python-list@python.org> (permalink)

Show all headers | View raw



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




Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Rule of order for dot operators? Cameron Simpson <cs@zip.com.au> - 2015-05-19 08:29 +1000
  Re: Rule of order for dot operators? Rustom Mody <rustompmody@gmail.com> - 2015-05-18 18:32 -0700
    Re: Rule of order for dot operators? Ron Adam <ron3200@gmail.com> - 2015-05-18 22:43 -0400
    Re: Rule of order for dot operators? Chris Angelico <rosuav@gmail.com> - 2015-05-19 16:25 +1000
    Re: Rule of order for dot operators? Ron Adam <ron3200@gmail.com> - 2015-05-19 14:02 -0400
  Re: Rule of order for dot operators? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2015-06-08 11:21 +0000
    Re: Rule of order for dot operators? Steven D'Aprano <steve@pearwood.info> - 2015-06-08 23:06 +1000

csiph-web