Passing a callable object to Thread

Jeff Schwab jeff at schwabcenter.com
Sat Feb 16 00:29:02 EST 2008


Paul Rubin wrote:
> Jeff Schwab <jeff at schwabcenter.com> writes:
>> Why not?  They seem intuitive to me.  I would find it weird if you
>> couldn't have 0-tuple, and even weirder if you couldn't have a
>> 1-tuple.   Maybe my brain has been warped by too much C++ code.
> 
> The idea is that a 2-tuple (of numbers, say) is a pair of numbers, a
> 3-tuple is three numbers, and a 1-tuple is one number.  That would
> mean a number and a 1-tuple of numbers are the same thing, not
> separate types.

No, that doesn't follow.  A set with one element is not the same thing 
as that element, a sequence of one element is not the same thing as that 
element, and a tuple with one element is not the same thing as that element.

> This is how most type systems treat tuples.

I take it you have particular systems in mind, but I've never used a 
programming language that works that way.

> Python does it a bit differently, treating tuples as something like
> frozen lists, so they support subscripting, iterator interfaces and so
> forth.  There are practical advantages to doing it that way, but it
> also leads to corners of oddness like the (a,) notation.

That "oddness" has nothing to do with tuples-of-one being strange, nor 
does it imply that tuples are fundamentally different from other 
collection types.  It is a historical accident of the fact that 
parentheses were already used to represent grouping for precedence by 
the time they were overloaded to represent tuples.  If bare-paren tuples 
had not been allowed (as bare sets are not allowed), then there would be 
no ambiguity, and no need for the (a,) notation.



More information about the Python-list mailing list