"Roy Smith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
In article <[EMAIL PROTECTED]>, Grant Edwards <[EMAIL PROTECTED]> wrote:
On 2004-12-29, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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
-- http://mail.python.org/mailman/listinfo/python-list