[Python-ideas] The non-obvious nature of str.join (was Re: sum(...) limitation)
Stephen J. Turnbull
stephen at xemacs.org
Mon Aug 11 02:20:53 CEST 2014
Terry Reedy writes:
> Addition of tallies (base 1 numbers) is concatenation.
Except that nobody actually tallies that way. In practice everybody
I've ever seen count to ten by tallying does something special for
fives (Americans tally four times then cross the four vertical strokes
with a fifth, Japanese build the character sei (正 == true)). So what
you're actually arguing is circular: if you represent a tally as a
string with a singleton alphabet, it behaves like a string. But in
Japanese it's actually a 5 element alphabet, and your homomorphism:
> For tallies, or strings, r and s, len(r+s) == len(r) + len(s).
fails.
I think that rather than focus on formal properties, we should look at
how sum is used in Python. For example, numerical sum is in fact an
attractive nuisance as long as floats are considered numbers. So
unless and until we deprecate floats, "formal sum" will always be
splintered into multiple functions.
As far as concat goes, I don't really see what advantage it has over
joiner.join, except in teaching. That might be enough for a builtin
in this case, since concatenating iterables of strings is a pretty
frequent operation in my experience.
More information about the Python-ideas
mailing list