2 ms·
Is the right to left order common to all array language? It sure doesn't help onboarding..
by renox 7y ago
Is the right to left order common to all array language?
It sure doesn't help onboarding..
- beagle3 7y agoIt is for APL and derived languages (APL, J, K, A, A+, Klong) And .. well, if you want C or Java, use C or Java. Quickly, which is higher precedence, "&" or ">" ? You may have memorized them, but many people get it wrong often enough. APL has a very simple and consistent rule: There is no precedence in an expression except paranthese, and you go right to left. And it may seem to not help with onboarding if you skim, but if you take the time it clicks quickly for most people, especially if you consider that "right to left" is actually "left of right", e.g. (note, a|b is the maximum of a and b, not the bitwise or) 1 + 2 * 3 + 4 | 5 is read and understood as: (1 + ...) applied to ((2 * ...) applied to ((3 + ...) applied to (4 | 5))) read another way (note: using python syntax) def f(x): return 1+x def g(x): return 2*x def h(x): return 3+x It is equivalent to f(g(h(max(4,5))) But one argument K/APL functions need no parentheses, so you would have written it f g h 4|5 But with "f", "g" and "h" inlined you get the original expression back. It is different - but it is simple and consistent without any arbitrary precedence and associativity rules. Also, it's not a new idea; APL predates every other programming language still in use except, perhaps, Fortran, Lisp and COBOL -- of which only Fortran uses operator precedence and associativity in the modern C/Algol sense. Lisp is also consistent (though with a different route than APL took). And I'm afraid to describe COBOL in fear that cthulu will rise.