Re:Klong: a Simple Array Language
by beagle3 on Monday December 23, 2019 @10:31PM
(#21869629)
It 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)))
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.
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)
is read and understood as: read another way (note: using python syntax) It is equivalent to But one argument K/APL functions need no parentheses, so you would have written it 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.