Discussion: Introducing new operators for matrix computation - general approach?

Damien jacques.bonhomme at advalvas.be
Wed Jul 19 20:35:24 EDT 2000


Andrew Henshaw wrote:
> 
> ...snip...
> I wonder if some of these problems could be approached in a more general
> manner.  What if Python could support the definition of operators in the
> same manner as functions? If that were the case then something like:
> 
> opr rDiv(X, y):
> 
> would define a new operator function that would work like:
> 
> b = X rDiv y
> 
> The big advantage would be that special purpose grammars could be easily
> imported.  The core language could be kept as simple as possible, but still
> be extensible in a  way that matters to a lot of people.
> 
> I suspect that whitespace would be required around these new 'operators',
> although many people already do that with regular operators.  Also, I'm not
> sure how you'd specify an operator that wasn't valid as a function name, but
> I can think of possibilities.
> 

I agree with a general approach.  Operator overloading is present in
Python 
and can create elegant solutions.  Extending the number of operators can
also make things clearer as there is no obligation to link a new type of
operation to an existing operator.
A general operator of the type .X  could avoid major parsing problem. 
When treating the dot operator, the X is present as parameter and is the
first 
character following the '.'   This avoids the necessity for blanks around
the 
operator.

Damien Fontaine




More information about the Python-list mailing list