Why tuple with one item is no tuple

Diez B. Roggisch deetsNOSPAM at web.de
Wed Mar 16 11:34:25 EST 2005


> I think he meant that Python should have introduced different operators
> for addition and sequence concatenation.

I reread his example and have to admit I'm confused: He complains about
having written his _own_ vector class - and concatenation and addition had
to use both + ?

He could have used | for concatenation instead. Apart from the concatenation
IMHO not being a mathematical founded operation on vectors.

I maybe was confused of him using + as bad example and then extending that
to *. But even more so my point is valid: If you forbid the overloading of
operators, you have to come up with even _more_ operator names, like ocaml
has *. and * for multiplication of floats and ints. So you end up with way
more clutter in the source, certainly more than the occasional extra comma.

>> Your opinion is wrong. It's because you seem to not have understood the
>> example: The expression (5 + 4) could be understood as 9 or as (9,). In
> 
> It should be understood as 9, but if integers etc implement the sequence
> protocol, 9 can be used just like a tuple
> (http://www.livejournal.com/users/glyf/29038.html).

The examples focus too much on numbers - if we use instead 

("foo")

we would get a iterable yielding ["foo",] or - as string already supports
iteration - ['f', 'o', 'o']. Which one to chose?

> 
> There have been other proposals where you could write 'for i in 5' etc.
> 
> I find this 'creative use of overloading' rather awful. But what the
> heck, I find list comprehension rather awful.

Well, the number of operators built into the language is limited - and I
actually prefer to have the possibility to overload these if I want to.
Nobody forces me - I could use

v1.concat(v2)

for two vectors v1, v2 if I wanted to.


-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list