[Python-Dev] defaultdict and on_missing()
Greg Ewing
greg.ewing at canterbury.ac.nz
Thu Mar 2 05:18:38 CET 2006
Guido van Rossum wrote:
> str.join() is an interesting case...
> Making it a
> string method is arguably the right thing to do, since this operation
> only makes sense for strings.
> The type of such a polymorphic function is easily specified:
> join(sequence[T], T) -> T, where T is a string-ish type.
I'd say it makes sense for any type that supports
concatenation (maybe that's what you mean by "string-ish"?)
This looks like a case where the xxx()/__xxx__() pattern
could be of benefit. Suppose there were a function
def join(seq, sep):
if hasattr(sep, '__join__'):
return sep.__join__(seq)
else:
# generic implementation
Then you could get nice fast type-specific implementations
for strings, bytes, etc., without being limited to those
types.
--
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | Carpe post meridiam! |
Christchurch, New Zealand | (I'm not a morning person.) |
greg.ewing at canterbury.ac.nz +--------------------------------------+
More information about the Python-Dev
mailing list