On Tue, Mar 25, 2014 at 2:56 PM, Rustom Mody <rustompm...@gmail.com >> I don't know about the difference between {} in set theory and Python, >> but the multiple uses of () actually boil down to two: > > In set theory {} makes sets > In python {} makes dictionaries
That's a backward-compatibility issue. Braces in Python meant a dictionary before it acquired a set type (at least, so I learned in history class - I wasn't using Python back then), so empty braces have to continue to mean empty dictionary. I sympathize with the confusion, but short of confusing everyone terribly by changing dicts to use something other than braces (maybe borrow Pike's mapping notation, ([ ])??), I don't really see a solution. >> 1) Grouping, which includes tuples; there's a special case whereby >> grouping nothing makes a zero-item tuple, but everything else is just >> the comma > >> 2) Functions (both definition and call) > >> Disambiguating them might be of some small value, but since they're >> the same in pretty much every language under the sun, it would feel > > What 'they'?? I dont get: If you are talking of disambiguating function > definition and call -- yeah thats overkill No no. Disambiguating grouping and fuction definition/call. There's no reason to have definition and call of functions differ. > If you are talking of overlap between tuples parentheses and function (call) > well consider > f(x,y) vs f((x,y)) vs (x,y) vs ((x,y)) > Paren vs tuples: why do we need to write (x,) not (x) > > All this is because () is doing triple-duty Tuples don't use parentheses. You only confuse yourself when you insist on that. The only case with parens that actually makes a tuple is the special empty tuple; imagine if that were given a name instead, like "Empty". That would solve that confusion. There's another minorly special case, and that's that the trailing comma is mandatory on a one-item tuple. In all others, it's optional, but the one-item tuple would be ambiguous otherwise. >>> len((1,2,3,)) 3 >>> len((1,2,)) 2 >>> len((1,)) 1 (By the way, bringing in another discussion: The comma isn't part of the element, nor is it exactly a separator, nor is it exactly a terminator. Just like a newline in a text file.) So the only ambiguity is between function calls and grouping. Tuples are just part of grouping, in that you need to disambiguate a one-tuple-arg function call from a multiple-arg function call - as in the above len() calls. And that's where I think it would be highly confusing to mandate something different. Suppose we used $( )$ for function calls, and ^( )^ for grouping: x = ^(1 + 2)^ * 3 y = range$(x)$ What have we gained by distinguishing them? Not a lot. If an open parenthesis immediately follows another token, it's calling that previous token; if it follows an operator, it's grouping. Seems pretty simple to me. (Cue the spate of emails pointing out something I've missed that breaks that rule, in which case call it a rule of thumb.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list