Python and generic programming

Terry Reedy tjreedy at
Sat Nov 20 17:18:40 CET 2004

"Isaac To" <iketo2 at> wrote in message 
news:87actcrhlo.fsf at

> "Terry" == Terry Reedy <tjreedy at> writes:
>>    Terry> Specialization goes in special methods -- the ones named
>>    Terry> __xxx__ -- of which there are now 50-100.

> No, you don't quite understand what the OP is asking for.

No, YOU are the one who does not understand, because you apparently did not 
do me the courtesy of reading my entire post, in which I quoted the 
question I answered.  Here again is the OP's question about *type* 
specialization *in Python*:

>>> If you have, for example, several data-types for matrices, how do you
>>> write code that will automatically find the right routine for quickly
>>> multiplying a vector by a diagonal matrix represented as a vector, and
>>> automatically call the right code for multiplying by a sparse matrix
>>> represented by some sparse coding, etc?

The has NOTHING to do with writing base cases in recursive C++ template 
metaprogramming (which, ironically, uses the compiler as an interpreter).

Although there may be other answers now and in the future, the answer I 
gave is the straightforward standard answer for Python today.

Terry J. Reedy 

More information about the Python-list mailing list