Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Woudn't it be more interesting to do it the other way around? Make the infix operator a prefix operator. For instance, in R you can do x+y or "+"(x,y). Sadly, you can't do "+"(x,y,z) and so on, but you can use it in this way:

    args = list(x,y)
    do.call("+",args)


Python has builtin alternate forms of all infix operators in the "operator" module:

    from operator import add
    add(x, y)
Like in your example, you can't simply give it more args (since infix operators are binary operators and may not be associative). But you could combine it with some other builtins like so:

    from operator import add
    reduce(add, [x, y, z])
Of course, for the specific case of addition, you can simply use the builtin "sum()" function, which is almost equivalent to above (sum() assumes an initial value of 0 by default, so sum(list) === reduce(add, list, 0))




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: