[Python-ideas] Is there a good reason to use * for multiplication?

Chris Angelico rosuav at gmail.com
Sat Oct 13 11:18:26 CEST 2012


On Sat, Oct 13, 2012 at 7:18 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On 13/10/12 19:05, Yuval Greenfield wrote:
>
>> A PEP for defining operators sounds interesting for 4.0 indeed. Though it
>> might be messy to allow a module to meddle with the python syntax.
>
> You mean more than classes already do? :)

Yes, more than classes already do. You could completely redefine
Python into another language.

Here, I wrote a program. It uses the letter d as an infix operator
that means "sum N random numbers up to M". You know the language, it's
Python same as you work with all the time! Oh, but I don't use + for
addition, I use $, and # is my "turn tuple into dictionary" operator,
and I use parentheses as a sort of C-style ternary operator.

But it's still Python, so you should be able to read and understand
the code, right?

I actually wrote up a language design spec to highlight what would
happen if this sort of thing were possible. And the writing of that
spec was what demonstrated to me how fundamentally BAD the idea was.

http://rosuav.com/1/?id=683

It could certainly be done. All you need to do is make abuttal of
three objects into second_object.__infix__(first_object, third_object)
and then handle the mess of prefix and postfix objects. I just don't
recommend ever doing it.

ChrisA



More information about the Python-ideas mailing list