[Python-ideas] Infix application of binary functions (original) (raw)
Dag Odenhall dag.odenhall at gmail.com
Thu Jul 22 00:37:05 CEST 2010
- Previous message: [Python-ideas] PEP 3151: Reworking the OS and IO exception hierarchy
- Next message: [Python-ideas] Infix application of binary functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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/
- Previous message: [Python-ideas] PEP 3151: Reworking the OS and IO exception hierarchy
- Next message: [Python-ideas] Infix application of binary functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]