[Python-ideas] Left division operator

Sturla Molden sturla at molden.no
Sat Jul 16 21:16:25 CEST 2011


I was wondering if anyone else has felt the need for a leftward division 
operator in Python. That is, y\x in addition to x/y. Thus the operators:
 y \ x
 y \\ x
Why the statement "y\x" is different from "x/y":
1. Opposite order of evaluation: This is important if evaluating one of 
the operands has side-effects.
2. In linear algebra, (Y**-1)*X is in general not equal to X*(Y**-1). 
Matrix and vector algebra in fundamental to computer graphics and 
scientific computing.
3. NumPy solves the lack of "\" operator by having a function 
np.linalg.solve. But using it in matrix expressions has the effect of 
mixing Pythonic infix operators with a Lisp-like prefix operator.
Two other issues:
1. The expressions
 y /= x
 y //= x
are evaluated in the same order as "y \ x", not "x / y".
2. The expressions
 y \= x
 y \\= x
 should perhaps be illegal due to implied side-effects on RHS.
Sturla


More information about the Python-ideas mailing list

AltStyle によって変換されたページ (->オリジナル) /