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


Groups > comp.lang.python > #90884

Re: Rule of order for dot operators?

From Ron Adam <ron3200@gmail.com>
Subject Re: Rule of order for dot operators?
Date 2015-05-19 14:02 -0400
References <55579886.3010001@cdreimer.com> <mailman.118.1431989304.17265.python-list@python.org> <fabab250-d7a5-49f4-a9ef-359bd003a607@googlegroups.com> <mje816$2kd$1@ger.gmane.org> <CAPTjJmqf4n4nzxs_TLBc8QAZsLkXRNxY_z8Gb0ZMmkf1kW5rpQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.150.1432058593.17265.python-list@python.org> (permalink)

Show all headers | View raw



On 05/19/2015 02:25 AM, Chris Angelico wrote:
> On Tue, May 19, 2015 at 12:43 PM, Ron Adam<ron3200@gmail.com>  wrote:
>> >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.

> If you want to implement the dot as an operator, you could do it by
> having a special syntactic element called an "atom", which is used for
> these kinds of identifier-like tokens. The dot operator could then
> take an object and an atom, and effectively return getattr(obj,
> stringify(atom)). I'm fairly sure this would result in the same syntax
> as Python uses.

I think it's better not to.   What practical things can be done if the dot 
was an operator and names after dots where parsed as atoms?

What I did was parse a name to a subtype of tuple with elements of strings. 
  [return name.with.dots] becomes this in memory after parsing.

     [keyword_object name_object]

Using dots as operators would make that...

     [keyword_object name_object dot_object atom_object dot_object
      atom_object]

This would require the interpreter to do in steps what a single function 
call can do all at once.

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