[Python-ideas] Infix application of binary functions

Dag Odenhall dag.odenhall at gmail.com
Thu Jul 22 00:37:05 CEST 2010

It could help readability if binary (arity of 2) functions could be
applied infix with some syntax. For example, borrowing from Haskell, the
backtick could be reintroduced for this purpose.

Good examples for this are isinstance and hasattr:

    if some_object `isinstance` Iterable:
    elif some_object `hasattr` '__iter__':

It is already possible[1] to make infix functions, but the solution is
a hack and requires functions to be marked as infix.

(The use of backticks is just an example borrowing from Haskell and
might not be optimal, although a benefit is that it isn't very noisy.)

[1] http://code.activestate.com/recipes/384122-infix-operators/

More information about the Python-ideas mailing list