5 ms·
Method calls are infix: target.method(argument, another) Here, the operation is `method` and the operands are `target`, `argument`, and `another. Note tha
by munificent 2y ago
Method calls are infix:
target.method(argument, another)
Here, the operation is `method` and the operands are `target`, `argument`, and `another. Note that the operation appears in the middle of the operands.
- Zambyte 2y agoFair point. I was considering `target.method` as the operator.
- munificent 2y agoIt depends on the language's semantics. Sometimes (as in Python), `target.method(a, b)` really is two separate operations, `target.method` (which returns a bound function) and then `<thing>(a, b)` which applies arguments to the result. Even then, it's still not a prefix operation. It's postfix.
- fuzztester 2y agoWhew. (Wipes sweat off brow). Things like this are mentioned, in some detail, in the O'Reilly book Python in a Nutshell, IIRC, in the first edition, which is what I have. Couldn't quite wrap my head around all the material in that chapter, TBH. But I still like to read about such stuff, and I do understand bits and pieces of it.
- anamax 2y agoIn Python, the "." in "target . method" is an infix operator. Note that the "(" in (a, b) is also an operator. (There is some special parsing because otherwise you could do things like args = (1, 2, b=3); target.method args.) As to whether <thing from target.method><thing from (a, b)> is postfix, I'm not sure how you get there. Yes, there's an implicit funcall at the end, but there's something similar with (+ a b) or ((. target method) (arglist a b)) and we wouldn't call them postfix.
- munificent 2y agoYou're right. Function application is essentially an infix `(` operator. Not sure how I got that wrong.
- rileyphone 2y agoNot really because the ordering is unambiguous given the parens. No need for operator precedence rules like PEMDAS.
- munificent 2y agoOh, you still have to worry about precedence. Consider: var x = 123 print(-x.abs()) Or even: print(-123.abs()) What do those print? Do they print the same thing?
- rileyphone 2y agoUnary operators are still operators. The integer parsing rules are probably different. In Lisp, -x would be a symbol, and the proper analog to -123 would be (- x) eg.
- munificent 2y agoI think we're in agreement. `-` and `.` are both operators and the language and user have to understand the relative precedence of them.