Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Why tuples use parentheses ()'s instead of something else like <>'s?

Reply
Thread Tools

Why tuples use parentheses ()'s instead of something else like <>'s?

 
 
John Roth
Guest
Posts: n/a
 
      12-29-2004

"Roy Smith" <> wrote in message
news:roy-...
> In article <41d2ce43$0$35731$>,
> Grant Edwards <> wrote:
>
>> On 2004-12-29, <> wrote:
>>
>> > Tuples are defined with regards to parentheses ()'s as everyone knows.

>>
>> Except they're not.
>>
>> >>> x = 1,2,3,4
>> >>> type(x)

>> <type 'tuple'>
>> >>>

>>
>> Tuples are defined by the infix comma "operator".

>
> Well, the syntax is a little more complicated than that. Commas don't
> form tuples in a lot of places:
>
> f (1, 2, 3) # function call gets three scalar arguments
> [1, 2, 3] # list of three integers, not list of tuple
> [x, 1 for x in blah] # syntax error, needs to be [(x, 1) for ...]
>
> I'm sure there are others. The meaning of "," depends on the context in
> which it appears.


This is true, however all three cases you mention are part
of the grammar. In any case, the function call syntax isn't
dependent on it following a function name; it's dependent
on it appearing where an operator is expected in the
expression syntax.

> In most cases, the parens around tuples are optional
> except when necessary to disambiguate, but there's one degenerate
> special case, the empty tuple (zerople?), where the parens are always
> required. It's just one of those little warts you have to live with.


That one doesn't require the comma, either. It's a very definite
special case.

> If Python had originally been invented in a unicode world, I suppose we
> wouldn't have this problem. We'd just be using guillemots for tuples
> (and have keyboards which made it easy to type them).


I suppose the forces of darkness will forever keep Python from
requiring utf-8 as the source encoding. If I didn't make a fetish
of trying to see the good in everybody's position, I could really
work up a dislike of the notion that you should be able to use
any old text editor for Python source.

There are a lot of Unicode characters that would be quite
helpful as operators. A left pointing arrow would be a vast
improvement over the equal sign for assignment, for example.
There wouldn't be any chance of mixing it up with the double
equal for comparisons. The same thing goes for multiplication
and division. We've allowed ourselves to be limited by the
ASCII character set for so long that improving that seems to be
outside of most people's boxes.

John Roth

 
Reply With Quote
 
 
 
 
Roy Smith
Guest
Posts: n/a
 
      12-29-2004
"John Roth" <> wrote:
> > If Python had originally been invented in a unicode world, I suppose we
> > wouldn't have this problem. We'd just be using guillemots for tuples
> > (and have keyboards which made it easy to type them).

>
> I suppose the forces of darkness will forever keep Python from
> requiring utf-8 as the source encoding. If I didn't make a fetish
> of trying to see the good in everybody's position, I could really
> work up a dislike of the notion that you should be able to use
> any old text editor for Python source.


You can't use "any old text editor" for Python source. You can only use
a hardware/software combination which supports the required character
set (which AFAICT means ASCII, including *both* cases of the alphabet).
You would probably find it difficult to enter Python code on a 029
keypunch, or an ASR-33, or even an IBM-3270.

Granted, those are all dinosaurs these days, but 30 years ago, they
represented the norm. At that time, C was just hitting the streets, and
it was a pain to edit on many systems because it used weird characters
like { and }, which weren't in EBCDIC, or RAD-50, or SIXBIT, or whatever
character set your system used. ASCII was supposed to solve that
nonsense once and for all, except of course for the minor problem that
it didn't let most people in the world spell their names properly (if at
all).

In any case, it's a good thing that Python can be edited with "any old
text editor", because that lowers the price of entry. I like emacs, the
next guy likes vi, or vim, or notepad, or whatever. Nothing is keeping
folks who like IDEs from inventing and using them, but I would have been
a lot less likely to experiment with Python the first time if it meant
getting one of them going just so I could run "Hello, world".

With google as my witness, I predict that in 30 years from now, ASCII
will be as much a dinosaur as a keypunch is today, and our children and
grandchildren will both wonder how their ancestors ever managed to write
programs without guillemots and be annoyed that they actually have to
type on a keyboard to make the computer understand them.
 
Reply With Quote
 
 
 
 
Reinhold Birkenfeld
Guest
Posts: n/a
 
      12-29-2004
Roy Smith wrote:
> "John Roth" <> wrote:
>> > If Python had originally been invented in a unicode world, I suppose we
>> > wouldn't have this problem. We'd just be using guillemots for tuples
>> > (and have keyboards which made it easy to type them).

>>
>> I suppose the forces of darkness will forever keep Python from
>> requiring utf-8 as the source encoding. If I didn't make a fetish
>> of trying to see the good in everybody's position, I could really
>> work up a dislike of the notion that you should be able to use
>> any old text editor for Python source.


> In any case, it's a good thing that Python can be edited with "any old
> text editor", because that lowers the price of entry. I like emacs, the
> next guy likes vi, or vim, or notepad, or whatever. Nothing is keeping
> folks who like IDEs from inventing and using them, but I would have been
> a lot less likely to experiment with Python the first time if it meant
> getting one of them going just so I could run "Hello, world".


Perl6 experiments with the use of guillemots as part of the syntax. I
shall be curious to see how this is accepted, of course only if Perl6 is
ever going to see the light of day, which is an exciting matter of its
own...

> With google as my witness, I predict that in 30 years from now, ASCII
> will be as much a dinosaur as a keypunch is today, and our children and
> grandchildren will both wonder how their ancestors ever managed to write
> programs without guillemots and be annoyed that they actually have to
> type on a keyboard to make the computer understand them.


Well, it's not clear if they will still "write" programs...

Reinhold
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      12-29-2004
On 2004-12-29, Reinhold Birkenfeld <reinhold-birkenfeld-> wrote:

> Perl6 experiments with the use of guillemots as part of the syntax.


As if Perl didn't look like bird-tracks already...

http://www.seabird.org/education/animals/guillemot.html
http://www.birdguides.com/html/vidli...Uria_aalge.htm

--
Grant Edwards grante Yow! There's enough money
at here to buy 5000 cans of
visi.com Noodle-Roni!
 
Reply With Quote
 
Rocco Moretti
Guest
Posts: n/a
 
      12-29-2004
wrote:

> Why tuples use parentheses ()'s instead of something else like <>'s?
>
> Please enlighten me as I really want to know.


So to summarize:

Commas define tuples, except when they don't, and parentheses are only
required when they are necessary.

I hope that clears up any confusion.
 
Reply With Quote
 
Reinhold Birkenfeld
Guest
Posts: n/a
 
      12-29-2004
Grant Edwards wrote:
> On 2004-12-29, Reinhold Birkenfeld <reinhold-birkenfeld-> wrote:
>
>> Perl6 experiments with the use of guillemots as part of the syntax.

>
> As if Perl didn't look like bird-tracks already...
>
> http://www.seabird.org/education/animals/guillemot.html
> http://www.birdguides.com/html/vidli...Uria_aalge.htm


Well,

(1,1,2,3,5) »+« (1,2,3,5,; # results in (2,3,5,8,13)

(>>+<< being an operator) just isn't something I would like to read in
my code...

Reinhold
 
Reply With Quote
 
Roy Smith
Guest
Posts: n/a
 
      12-29-2004
In article <>,
Reinhold Birkenfeld <reinhold-birkenfeld-> wrote:

> >>+<< being an operator


Looks more like a smiley for "guy wearing a bowtie"
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      12-29-2004
On 2004-12-29, Reinhold Birkenfeld <reinhold-birkenfeld-> wrote:

>>> Perl6 experiments with the use of guillemots as part of the syntax.

>>
>> As if Perl didn't look like bird-tracks already...
>>
>> http://www.seabird.org/education/animals/guillemot.html
>> http://www.birdguides.com/html/vidli...Uria_aalge.htm

>
> Well,
>
> (1,1,2,3,5) »+« (1,2,3,5,; # results in (2,3,5,8,13)


I was pretty sure that « and » were guillmots, but google sure
preferred the sea bird when I asked it.

--
Grant Edwards grante Yow! I've been WRITING
at to SOPHIA LOREN every 45
visi.com MINUTES since JANUARY 1ST!!
 
Reply With Quote
 
Dan Sommers
Guest
Posts: n/a
 
      12-29-2004
On 29 Dec 2004 21:03:59 GMT,
Grant Edwards <> wrote:

> On 2004-12-29, Reinhold Birkenfeld <reinhold-birkenfeld-> wrote:
>>>> Perl6 experiments with the use of guillemots as part of the syntax.
>>>
>>> As if Perl didn't look like bird-tracks already...
>>>
>>> http://www.seabird.org/education/animals/guillemot.html
>>> http://www.birdguides.com/html/vidli...Uria_aalge.htm

>>
>> Well,
>>
>> (1,1,2,3,5) »+« (1,2,3,5,; # results in (2,3,5,8,13)


> I was pretty sure that « and » were guillmots, but google sure
> preferred the sea bird when I asked it.


They're guillemets (with an "e"); this is a [relatively] well-known
Adobe SNAFU. (A quick google search or two failed to find an
authoritative reference, but I know that such references are out there
somewhere.)

Regards,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Never play leapfrog with a unicorn.
 
Reply With Quote
 
seberino@spawar.navy.mil
Guest
Posts: n/a
 
      12-29-2004
> There just isn't enough
> neat-looking punctuation in the ASCII character set.


Alex

I can't thank you enough for your reply and for everyones' great info
on this thread. The end of your email gave a rock solid reason why it
is impossible to improve upon ()'s for tuples....

*There simply isn't enough good candidates in ASCII.*

Moving to Unicode has pros
and cons but your defense of parens assuming ASCII is perfect.
Thanks again.

Chris

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dictionaries with tuples or tuples of tuples Jon Reyes Python 18 02-19-2013 03:56 AM
tuples within tuples korovev76@gmail.com Python 12 10-27-2007 08:16 PM
When are immutable tuples *essential*? Why can't you just use lists *everywhere* instead? seberino@spawar.navy.mil Python 27 04-25-2007 02:55 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Different tuples to one container? (One type of a pointer to point to different kinds of tuples?) fff_afafaf@yahoo.com C++ 5 10-05-2006 11:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57