> Programming Languages > Python
Various Topics Home | Disclaimer | Report Adult Posts

Various Topics on Python



Python - "__brace__ (PEP?)" in Programming Languages


Old 05-09-2005   #1
..m.. ..ro..
 
Default __brace__ (PEP?)

Hello All,

If "__call__" allows anobject() and "__getitem__" allows anobject[arange], why
not have "__brace__" (or some other, better name) for anobject{something}.
Such braces might be useful for cross-sectioning nested data structures:

anary = [[1,2,3],[4,5,6]]

anary{2} ==> [3,6]


or for a list of dictionaries:

alod = [{"bob":1,"ted":2,"carol":3},{"bob":4,"ted":5,"caro l":6}]

alod{"ted"} ==> [2,5]


or, heck, a dictionary of lists:

adol = {"bob":[1,2,3],"carol":[4,5,6],"alice":[7,8,9]}

adol{1} ==> {"bob":2, "carol":5, "alice":8}


Though I positively can not see what is wrong with this suggestion, I am sure
this will raise more than a few objections. Please bash my naivete publicly
on the list.

Some preemptive observations

1. on syntactic ambiguity (i.e. "braces already used")

[] ==> used for both list and getitem (both for dict AND list)
() ==> used for tuple, callable, grouping

2. on functional ambiguity (i.e. "function not implicit"):

Q. What exactly does it mean to call an instance of cl*** MyCl***?
A. Whatever the author of MyCl*** wanted it to mean.

etc.

Also, if this exists already, I apologize because I have not seen it in any
Python code before and I wouldn't know what to call it for googling.

James


--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
Old 05-09-2005   #2
..y ..i..
 
Default Re: __brace__ (PEP?)

James Stroud <jstroud@mbi.ucla.edu> wrote:
> why not have "__brace__" (or some other, better name)
> for anobject{something}. Such braces might be useful for
> cross-sectioning nested data structures:


This seems like a pretty esoteric operation to devote a bit of syntax to.
It doesn't seem like something people want to do very often.
 
Old 05-09-2005   #3
..m.. ..ro..
 
Default Re: __brace__ (PEP?)

On Sunday 08 May 2005 05:15 pm, Roy Smith wrote:
> This seems like a pretty esoteric operation to devote a bit of syntax to.
> It doesn't seem like something people want to do very often.


Similar to __call__, I don't think that this syntax would be neccessarily
devoted to any particular operation. I'm simply offering cross-sectioning as
a potential and intuitive operation that would benefit from a shortcut. The
main point is that using braces after a name is not defined right now and I
think that they could be put to good use.

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
Old 05-09-2005   #4
..y ..i..
 
Default Re: __brace__ (PEP?)

In article <mailman.177.1115599072.29826.python-list@python.org>,
James Stroud <jstroud@mbi.ucla.edu> wrote:

> On Sunday 08 May 2005 05:15 pm, Roy Smith wrote:
> > This seems like a pretty esoteric operation to devote a bit of syntax to.
> > It doesn't seem like something people want to do very often.

>
> Similar to __call__, I don't think that this syntax would be neccessarily
> devoted to any particular operation. I'm simply offering cross-sectioning as
> a potential and intuitive operation that would benefit from a shortcut. The
> main point is that using braces after a name is not defined right now and I
> think that they could be put to good use.
>
> James


One of the nice things about Python is that the syntax is relatively
simple, and words are generally favored over punctuation. There's lots of
punctuation which is not currently used, but that doesn't mean it's a good
idea to go off inventing meanings for it. I supposed we could have:

foo->bar ==> foo.__arrrow__(bar)
foo$bar ==> foo.__dollar__(bar)
foo#bar ==> foo.__hash__(bar)
foo::bar ==> foo.__scope__(bar)

and so on down the list of non-alphanumeric characters, but the result
wouldn't be anything most of us would recognize as Python.
 

Thread Tools
Display Modes





Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0