Iterator addition

Bengt Richter bokr at oz.net
Sun Nov 13 19:38:57 EST 2005


On Sun, 13 Nov 2005 17:28:59 -0600, jepler at unpythonic.net wrote:
[...]
>
>On Sun, Nov 13, 2005 at 09:44:43PM +0000, Bengt Richter wrote:
>> even if expr1 had a __unaryop__ method,
>>     expr1 - expr2
>> could not become
>>     expr1.__unaryop__(-expr2)
>> unless you forced the issue with
>>     expr1 (-expr2)
>
>as opposed to being a function call?  I don't think you've solved the ambiguity problem yet.
>
Oops ;-) Ok. Parens to control evaluation order in expression sequences could use the illegal
attribute trailer syntax expr1 .(expr2) so that would be

      expr .(-expr)

And the previous MINUS thing would become

     MINUS .(a MINUS b)

Not as pretty, but I guess workable when actually needed.

Anyway, to give an idea of possibilities, matrix ops could
be written nicely to operate on lists and lists of lists
(or duck-equiv objects) as an alternative to having e.g.
a matrix class with __POW__(-1) and __MUL__ defined,
and where you might use a matrix class and write

    a41 = m44**-1 * m41

you could operate on duck-lists writing something like

    a41 = m44 INV MM m41

where (sketching still ;-)

    class INV(MatrixOps):
        """postfix matrix inverse operator"""
        @classmethod
        def __pfunaryop__(cls, m):
             # mx inverse here
             return cls.inverse(m)

    class MM(MatrixOps):
        """binary matrix multiply operator"""
        @classmethod
        def __binaryop__(cls, left, right):
             # mx product here
             return cls.product(left, right)

Regards,
Bengt Richter



More information about the Python-list mailing list