Tuple Format?
warrenk at Zem.Zem
warrenk at Zem.Zem
Tue Sep 5 20:36:11 EDT 2000
Steve Holden <sholden at holdenweb.com> wrote:
>
>This thread has become a veteran, but ironically I have not yet seen
>a SINGLE suggestion which would be easier to explain to novices than
>the current syntax. Anything which tries to use the same token to open
>AND close a tuple is doomed to failure when nested tuples are needed.
>
>Ho, hum.
>
>regards
> Steve
Isn't this concern about bracketing tuples a red herring?
Except for an empty tuple, tuples are defined by the comma.
Parentheses are only needed to resolve ambiguities in argument
lists,
foo(x, (a,tuple))
lists,
[1, (2, 3)]
and to group tuples inside tuples.
1, (2, 3)
The first two are because the comma is used for reasons other
than tuple creation. I think the last example is unavoidable.
So, just come up with another tuple delimiter. Let's use a
semicolon, I never use them anyway.
foo(x, a;tuple)
[1, 2;3]
1;(2;3)
That just leaves the problem of an empty tuple. Why not this?
empty_tuple = ;
The inconsistancy of trailing commas or semicolons (tuple
operators?) can be solved by requiring them.
one_item_tuple = 1;
two_item_tuple = 1;2;
Now tuple construction can be explained by saying:
The tuple operator - ';' - concatenates the preceeding
item into a tuple.
[item] ; [item ; ...]
Is that simple enough?
Would it work?
Does any of this thread really matter? :)
(BTW, I really am curious if it would work.)
Warren
More information about the Python-list
mailing list