[Python-ideas] π = math.pi

Joshua Morton joshua.morton13 at gmail.com
Sat Jun 3 01:59:06 EDT 2017


For reference, haskell is perhaps the closest language to providing
arbitrary infix operators, and it requires that they be surrounded by
backticks. That is

    A `op` B

is equivalent to

    op(A, B)

That doesn't work for python (backtick is taken) and I don't think anything
similar is a good idea.

On Sat, Jun 3, 2017 at 1:56 AM 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.
>
> 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.
>
> Not a stupid question, but one for which the answer is "definitely not
> like that".
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170603/a69e0e5e/attachment.html>


More information about the Python-ideas mailing list