MRAB | 1 Feb 2012 02:06

Re: Dict-like object with property access

On 01/02/2012 00:42, Ethan Furman wrote:
> Terry Reedy wrote:
>>  On 1/31/2012 1:06 PM, Eric Snow wrote:
>>
>>>  +1 for reconsidering the d.[name] / d.(name) / d!name syntax.
>>
>>  d.[name] is too much like d[name] The . that modifies the meaning of
>>  'name' is too far away.
>>
>>  d.(name) is like d.name except to me the () means to use the value of
>>  name rather than 'name' itself. This is just what you are trying to say.
>>  I believe () is used elsewhere with that meaning. I could live with this.
>>
>>  d!name has the advantage? of no brackets, but just looks crazy since !
>>  meant 'not' in Python.
>
>
> I'm not a fan of any of the .[], .(), .{} patterns, nor of .! .
>
.() looks the most sensible to me.

> What about the colon?
>
> d:name  #use the value of name
>
Surely you jest? :-)
Simon Sapin | 1 Feb 2012 09:06
Picon

Re: Dict-like object with property access

Le 01/02/2012 02:06, MRAB a écrit :
>> >  I'm not a fan of any of the .[], .(), .{} patterns, nor of .! .
>> >
> .() looks the most sensible to me.
>

If .[] looks like indexing, .() looks like calling. (I’m not for or 
against either of these, just pointing out that they have the same problem.)

Regards,

--

-- 
Simon Sapin
Joao S. O. Bueno | 1 Feb 2012 12:33
Picon
Favicon
Gravatar

Re: Dict-like object with property access

On Wed, Feb 1, 2012 at 6:06 AM, Simon Sapin <simon.sapin <at> kozea.fr> wrote:
> Le 01/02/2012 02:06, MRAB a écrit :
>
>>> >  I'm not a fan of any of the .[], .(), .{} patterns, nor of .! .
>>> >
>>
>> .() looks the most sensible to me.
>>
>
> If .[] looks like indexing, .() looks like calling. (I’m not for or against
> either of these, just pointing out that they have the same problem.)

Still, there should be something with a closing token.
Try to imagine three of these in a chain, if the syntax is a colon:

name1:name2:name3:name4 -> which could mean either of:

name1:(name2:(name3:name4)), (name1:name2):(name3.name4)
and so on  - (not to mention other expressions involving names, though these
would be less ambiguous due to to operator precedence.

  js
 -><-

>
> Regards,
>
> --
> Simon Sapin
>
(Continue reading)

Paul Moore | 1 Feb 2012 14:05
Picon
Gravatar

Re: Dict-like object with property access

On 1 February 2012 11:33, Joao S. O. Bueno <jsbueno@...> wrote:
> Still, there should be something with a closing token.
> Try to imagine three of these in a chain, if the syntax is a colon:
>
> name1:name2:name3:name4 -> which could mean either of:
>
> name1:(name2:(name3:name4)), (name1:name2):(name3.name4)
> and so on  - (not to mention other expressions involving names, though these
> would be less ambiguous due to to operator precedence.

No more so than a.b.c.d.e

I would expect a:b to behave exactly the same as a.b, Except that it
uses getitem rather than getattr under the hood (was that the
proposal? I'm completely confused by now as to what this new syntax is
intended to achieve...)

But I don't like the idea in any case, so I remain -1 on the whole proposal.

Paul.
Massimo Di Pierro | 1 Feb 2012 14:32
Picon

Re: Dict-like object with property access

Using x:[....] wouldn't it create ambiguities when parsing (lambda x:[....])?

How about x. as a shortcut for x.__dict__ so we can do

x.key -> x.__dict__['key'] 
x.[key] -> x.__dict__[key]
x..keys() -> x.__dict__.keys()
x..values() -> x.__dict__.values()

for attribute in x.:
     print 'x.'+attribute

and leave open the possibility of 3 dots for for ranges
1...5 -> range(1,5)
1,2...10 -> range(1,10,2-1)

On Feb 1, 2012, at 7:05 AM, Paul Moore wrote:

> On 1 February 2012 11:33, Joao S. O. Bueno <jsbueno@...> wrote:
>> Still, there should be something with a closing token.
>> Try to imagine three of these in a chain, if the syntax is a colon:
>> 
>> name1:name2:name3:name4 -> which could mean either of:
>> 
>> name1:(name2:(name3:name4)), (name1:name2):(name3.name4)
>> and so on  - (not to mention other expressions involving names, though these
>> would be less ambiguous due to to operator precedence.
> 
> No more so than a.b.c.d.e
> 
(Continue reading)

Masklinn | 1 Feb 2012 14:44

Re: Dict-like object with property access

On 2012-02-01, at 14:32 , Massimo Di Pierro wrote:
> Using x:[....] wouldn't it create ambiguities when parsing (lambda x:[....])?
> 
> How about x. as a shortcut for x.__dict__ so we can do
> 
> x.key -> x.__dict__['key'] 
> x.[key] -> x.__dict__[key]
> x..keys() -> x.__dict__.keys()
> x..values() -> x.__dict__.values()
> 
> for attribute in x.:
>     print 'x.'+attribute
> 
> and leave open the possibility of 3 dots for for ranges
> 1...5 -> range(1,5)
> 1,2...10 -> range(1,10,2-1)

Yeah, readability schmeadability.

Also, 

    >>> 1..__int__()
    1

that's going to look good.
Georg Brandl | 1 Feb 2012 20:35
Picon
Gravatar

Re: Dict-like object with property access

Am 01.02.2012 14:32, schrieb Massimo Di Pierro:
> Using x:[....] wouldn't it create ambiguities when parsing (lambda x:[....])?
> 
> How about x. as a shortcut for x.__dict__ so we can do
> 
> x.key -> x.__dict__['key'] 
> x.[key] -> x.__dict__[key]
> x..keys() -> x.__dict__.keys()
> x..values() -> x.__dict__.values()
> 
> for attribute in x.:
>      print 'x.'+attribute
> 
> and leave open the possibility of 3 dots for for ranges
> 1...5 -> range(1,5)

Actually no, because 1. is a float literal. So

1...keys()

would already be valid, and you have to use four dots for ranges.
I would suggest five to be on the safe side (plus it has as many
dots as there are letters in "range", therefore easy to remember).

SCNR,
Georg

Gmane