[Python-3000] Python 3000 Status Update (Long!)
Gareth McCaughan
gareth.mccaughan at pobox.com
Thu Jun 21 00:58:15 CEST 2007
On Wednesday 20 June 2007 18:12, Nicko van Someren wrote
(about summing strings, etc.)::
> The need to have an explicit 'start' value just seems wrong. It's
> horribly inconsistent. Things that can be added to integers work
> without initialisers but things that can be added to each other (for
> instance numbers in number fields or vectors in vector spaces) can
> not.
I think there's another reason for not allowing sum on arbitrary
objects, which I find more convincing (though still maybe not
convincing enough):
sum([1,1,1]) = 3
sum([1,1]) = 2
sum([1]) = 1
sum([]) = 0
sum(["a","a","a"]) = "aaa"
sum(["a","a"]) = "aa"
sum(["a"]) = "a"
sum([]) = ????
That is: if you're writing code that expects sum() to do something
sensible with lists of strings, you'll usually need it to do something
sensible with *empty* lists of strings -- but that isn't possible,
because there's only one empty list and it has to serve as the empty
list of integers too.
> I think in most people's minds the 'sum' operation is like an
> evaluation of "+".join(...), you are sticking an addition operation
> between the elements of the list. The need to have an explicit
> initial value means that sum() is not the sum function for anyone who
> does math in any sort of non-standard number space.
If you allow the elements of your number field to be added to
plain ol' 0, then sum() will work fine for them, no? (But that
isn't such a plausible prospect for vectors.)
--
Gareth McCaughan
More information about the Python-3000
mailing list