On the subject of custom infix operators, there are at least two packages
on PyPI that allow you to do this already:

https://pypi.org/project/funcoperators/
https://pypi.org/project/infix/

On Sat, May 2, 2020 at 12:51 AM Steven D'Aprano <st...@pearwood.info> wrote:

> On Fri, May 01, 2020 at 07:41:57PM -0700, Andrew Barnert wrote:
>
> > The most obvious way to do it is borrowing straight out of Haskell, so
> this:
> >
> >     x `spam` y
> >
> > … compiles to exactly the same code as this:
> >
> >     spam(x, y)
>
> I really, really want to like that syntax, but I can't. The backticks
> get in the way. It's not that I don't like backticks. I do. But to the
> degree that "infix operators" are words:
>
>     x is y
>
> rather than symbols, the backticks get in the way of it looking like a
> word:
>
>     x `is` y
>
> Even though they're only grit on Tim's monitor *wink* nevertheless they
> stand out too much for my liking. (Maybe I wouldn't think so if my
> native language used more accents?)
>
> So I'm afraid that I can't get past the idea that for a good looking,
> attractive syntax, you can either go whole-hog for Hypertalk-like
> natural(-ish) language syntax:
>
>    the number of words of line 1 of text
>
> or functional notation:
>
>    len(words(lines(text)[0]))
>
> but cramming them into the same language with backticks or dollar signs
> or some other sygil might be technically possibly but aesthetically
> ugly.
>
> (Likewise I like Forth-like RPN code, but I don't think trying to cram
> it into Python would look good.)
>
>
> [...]
> > For this particular use case:
> >
> >     isa = isinstance
> >     thing `isa` Fruit and not thing `isa` Apple
> >
> > … honestly, the lack of any parens here makes it seem harder to read,
> > even if it is a bit closer to English.
>
> Do you think the same about this?
>
>     thing is None and not obj is None
>
> If not, perhaps its just familiarity. Or the backticks getting in the
> way for you too :-)
>
>
> --
> Steven
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/YMYFH3RB35CL6VXHPXS5Z3HJYJMQZHTW/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/RY6KL7E2JJP5MLLLWQS4ERSPU5FWGCYH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to