[Python-ideas] Another attempt at a sum() alternative: the concatenation protocol

Ronald Oussoren ronaldoussoren at mac.com
Tue Jul 16 09:58:15 CEST 2013


On 16 Jul, 2013, at 8:50, Nick Coghlan <ncoghlan at gmail.com> wrote:

> I haven't been following the sum() threads fully, but something Ron
> suggested gave me an idea for a concatenation API and protocol. I
> think we may also be able to use a keyword-only argument to solve the
> old string.join vs str.join problem in a more intuitive way.
> 
>    def concat(start, iterable, *, interleave=None):
> 
[...]
> 
> A simple "use sum for numbers, concat for containers" approach is
> simpler and clearer than trying to coerce sum into being fast for both
> when its assumptions are thoroughly grounded in manipulating numbers
> rather than containers.

I like the basic idea, using 'concat' to concatenate sequences and strings
is clear than using sum and the __contact__ (or singledispatch) protocol
has a nice way to make this fast enough for any type without trying to push
knowlegde about all types in the implementation of concat.

Ronald


More information about the Python-ideas mailing list