[Python-ideas] Left division operator

Stefan Behnel stefan_ml at behnel.de
Sun Jul 17 16:49:51 CEST 2011


Nick Coghlan, 17.07.2011 09:22:
> On Sun, Jul 17, 2011 at 5:16 AM, Sturla Molden wrote:
>> 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.
>
> 1. Python evaluates operands in left to right fashion. Breaking this
> requires extremely good justification (The ternary operator is the
> only current exception that doesn't involve a closure, and that's only
> because the alternatives were all even worse).

It would still be evaluated left-to-right, as far as I understand Sturla. 
Note that he swapped the x and y operands in the two examples for \ and /. 
So both operators would go left-to-right, only the resulting division would 
be reversed in the backslash case, thus dividing by the operand that was 
evaluated *first*.

That being said, I agree with the comments below.


> 2. Backslash is not a viable operator choice. Ever. (cf. Carl's answer)
>
> 3. The use case is far too narrow to be baked into the core language.
> If it's beyond high school mathematics, syntactic support within
> expressions is highly unlikely to ever be provided.

Plus, I don't find this syntax very readable, but I guess that just sits on 
top of your above two arguments.

Stefan




More information about the Python-ideas mailing list