A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-March/052146.html below:

[Python-Dev] Rationale for sum()'s design?

[Python-Dev] Rationale for sum()'s design? [Python-Dev] Rationale for sum()'s design?Michael Walter michael.walter at gmail.com
Sun Mar 13 20:19:05 CET 2005
That is like Lisp's +, must be good :P

Michael


On Sun, 13 Mar 2005 08:38:42 -0800, Guido van Rossum
<gvanrossum at gmail.com> wrote:
> There are a few design choices we could have made for sum(); in
> particular, for non-empty sequences we could not have used the
> identity element (the optional second argument). As it is, we get
> unjustified but understandable complaints that sum() "only supports
> numbers". An alternative design could have returned:
> 
> - the identity (defaulting to 0) if the sequence is empty
> - the first and only element if the sequence only has one element
> - (...(((A + B) + C) + D) + ...) if the sequence has more than one element
> 
> This has surprises too (in particular of returning 0 when invoked
> without overriding the identity argument for a seqence of addable
> non-numbers) but works without using the second argument for a larger
> set of inputs I believe it is often used in such a way that the input
> is known to be non-empty).
> 
> I'd be happy to be pointed to a past discussion where this was
> considered and rejected with a good reason; then I can post that to
> the blog (where the deficiency in sum() is being berated a bit
> excessively).
> 
> --
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/michael.walter%40gmail.com
>
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4