Steve Holden wrote:
> Paul Rubin wrote:
>> Steve Holden <[EMAIL PROTECTED]> writes:
>>> Assuming you're right, what alternative would you suggest? Would it
>>> allow parenthesized expressions to retain their customary meaning?
>>
>> It is kind of weird that there is even such a thing as a 1-tuple.
> 
> I agree that zero-length and singleton tuples don't make a great deal of 
> sense semantically.

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.

In C++, it's very common to define data structures that have no members; 
the moral equivalent of an empty tuple:

        struct S { };

I recently did this in C, and was surprised to see this message from gcc:

        main.c:1: warning: struct has no members

It's also common in C++ to treat a stand-alone object as an array of 
length 1.  This is useful because any function defined to take a 
sequence of input can easily be given a single element instead:

        int proto = 5;
        std::vector<int> v(&proto, &proto + 1);

It strikes me that 1-tuples could serve the same purpose.  It's common 
now for functions to be defined to take single elements, with client 
code using loops to process sequences:

        for item in sequence:
                process(item)

If functions were instead defined to take sequences, then client code 
would be simplified, especially for common tasks like processing lines 
of input.

        process(sequence)

On occasions when only a single item were to be processed, a 1-tuple 
would serve as a nice syntactic adapter:

        process((item,))
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to