3 ms·
Is there a reason why APL languages all fold right? I mean other than genealogical, as in they fold right because APL does. Does it offer compelling advantages?
by samatman 3y ago
Is there a reason why APL languages all fold right? I mean other than genealogical, as in they fold right because APL does. Does it offer compelling advantages?
As an outsider it looks like wasted novelty budget. There's already a lot of new things to learn and get used to in an APL school array language, and then on top of that you have to learn to read them right to left.
- zuser567 3y agoI imagine it’s because reverse Polish notation is commonly accepted to be superior.
- amluto 3y agoOn that note, why do array languages use terse notation and avoid newlines? Regexes do this too, but at least Perl 6 / Raku is pushing for a multi-line form. There are even initiatives to give lisps friendlier syntax.
- lokedhs 3y agoI'd argue it's partly because of tradition. If you look at early APL code, including Iverson's earliest papers, it's written with pretty much zero spaces (well, except for where spaces are required). A lot of APL programmers continue this tradition, and it works for them. Not everybody does it though. I'm one of those people that adds spaces and newlines to try to make the code more clear for myself. As an example of the kind of code I tend to write, here's the code for the Kap output formatter: https://codeberg.org/loke/array/src/branch/master/array/standard-lib/output3.kap https://codeberg.org/loke/array/src/branch/master/array/stan... Of course, if you don't know what the symbols mean, a lot of it is probably still impenetrable, but I think this code is less dense than your typical APL code.
- t-3 3y agoIt's about simple and consistent order of operations. There are no precedence rules to remember other than that, so it reduces errors and improves readability compared to a complex formula written in standard notation, where you would have to read the entire thing to know which parts are calculated first.
- gitonthescene 3y agoNot all array languages fold right. K's reduce is a left fold and BQN has a mix of both. My understanding is that a right fold was chosen because it's more expressive. You get alternating sums when folding subtraction with a right fold and something less interesting if you use a left fold. FWIW, that(s my understanding of the history. I don't actually think the argument is very compelling.