[Python-ideas] π = math.pi

Pavol Lisy pavol.lisy at gmail.com
Sat Jun 3 03:22:14 EDT 2017


On 6/3/17, Chris Angelico <rosuav at gmail.com> wrote:
> On Sat, Jun 3, 2017 at 3:42 PM, Pavol Lisy <pavol.lisy at gmail.com> wrote:
>> Sorry for probably stupid question! Is something like ->
>>
>>     class A:
>>         def __oper__(self, '⊞', other):
>>             return something(self.value, other)
>>
>>     a = A()
>>     a ⊞ 3
>>
>> thinkable?
>
> No, because operators need to be defined before you get to individual
> objects, and they need precedence and associativity. So it'd have to
> be defined at the compiler level.

Thanks for clarifying this point.

Sorry for another stupid question: coding import machinery couldn't be
used too, right? (I mean something like hylang.org ) Because ast could
not understand these operators (and precedence and associativity)?

BTW there could be also question about "multipliability". I mean
something like a↑↑↑n ( see
https://en.wikipedia.org/wiki/Knuth%27s_up-arrow_notation )

> Also, having arbitrary operators gets extremely confusing. It's not
> easy to reason about code when you don't know what's even an operator.

I was thinking about it, but python is like this! You couldn't be
really sure what is operator + doing!  :)

And it could be much easier to learn what some operator means in some
library than for example understand async paradigm. (at least for some
people)

> Not a stupid question, but one for which the answer is "definitely not
> like that".

Thanks again! :) Although I am not sure it is definitely impossible I
see that it is pretty pretty difficult.


More information about the Python-ideas mailing list