[PEP draft 2] Adding new math operators

Robin Becker robin at jessikat.fsnet.co.uk
Wed Aug 9 06:34:17 EDT 2000


In article <3991243D.D987955 at fft.be>, Gregory Lielens
<gregory.lielens at fft.be> writes
...
>> I think this approach deserves a much more serious study, because it
>> is much more "Python-like", and requires no syntactical changes.
>> Lobbying for attributes on number types will be a lot easier than
>> lobbying for new operators.
>
>Yep, I agree...I hope this message qualify as a part of this study!
...
As I understand it the classes involved determine what happens. There
fore in general if A is KlassA and B is KlassB then

        A*B --> KlassA.__mul__(A,B) else KlassB.__rmul__(B,A)
        B*A --> KlassB.__mul__(B,A) else KlassA.__rmul__(A,B)

so in general you won't be able to determine in a module what happens
by switching a flag.

You can do this sort of thing if you have an intermediate abstract class
that is neither KlassA or KlassB, you can then do stuff like build the
abstract syntax tree of the computation or whatever. In Ada they do this
sort of thing all the time to accomplish differentiation, optimal matrix
multiplication ordering etc. Doing it dynamically is more difficult. 
-- 
Robin Becker



More information about the Python-list mailing list