Python and generic programming

Isaac To iketo2 at netscape.net
Sun Nov 21 00:05:05 EST 2004


>>>>> "Terry" == Terry Reedy <tjreedy at udel.edu> writes:

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

    Terry>  you apparently did not do me the courtesy of reading my
    Terry> entire post, in which I quoted the question I answered.

I admit that I didn't read your mail very carefully when I write my
response.  I did that immediately afterwards, and my post didn't make
sense even to myself.  So I cancel that post a minute after making it,
although apparently my cancel posting didn't go as far as my response.

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

I see no problem using the compiler as an interpreter.  Indeed, I
think C++ should make it more explicit and allow one to do things in
compile time as easily as one can do at run-time (e.g., why only
support integers, and why one have to do recursions instead of
loops?).  But this is a Python group, not a C++ group, so such things
are off-topic here.

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

On the other hand, I didn't agree with this.  Your answer basically
said "define a member function called __mul__ for each class you
have", which I don't think is what the OP asked for.  First, nothing
in the original post said he wants the function to be used with
operator syntax, so __mul__ or other __xxx__ member functions should
be considered off-topic.  Second, the OP asked for "specialization",
and, as an example, asked for a way to cause the system "automatically
finds the right routine for [one type], and automatically call the
right code for [another type]".  Your answer involves defining a
method for each type one creates, which (1) is not automatic, and (2)
requires one to modify the class, which is not what is expected by a
C++ programmer who are used to template functions and specialization.

Template specialization is a dispatch mechanism that is external to a
class.  You probably mean "such mechanism is missing in Python".  I'm
not quite sure that is correct, though.

Regards,
Isaac.



More information about the Python-list mailing list