diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-10-06 21:08:46 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-10-06 21:08:46 -0400 |
| commit | ca98dc86beec19c73ab2564ba78c102ecebf8d90 (patch) | |
| tree | fa656c57236e5cd3e7af8d68db2ea87d60783e63 | |
| parent | 2ce2dc40702431ef3d3ffece9e2f6f8b883ac6c5 (diff) | |
Some note on left-to-right
| -rw-r--r-- | commentary/ltr.md | 25 | ||||
| -rw-r--r-- | docs/commentary/ltr.html | 24 |
2 files changed, 49 insertions, 0 deletions
diff --git a/commentary/ltr.md b/commentary/ltr.md new file mode 100644 index 00000000..b29e606a --- /dev/null +++ b/commentary/ltr.md @@ -0,0 +1,25 @@ +*View this file with syntax highlighting [here](https://mlochbaum.github.io/BQN/commentary/ltr.html).* + +# Left to right ordering? + +APL's right-to-left evaluation order is something many programmers ask about, and something I've questioned personally as well. In fact the first significant language I designed, called [I](https://github.com/mlochbaum/ILanguage), used a left to right ordering for all code. + +I settled fairly quickly on sticking to the left to right ordering in BQN. I'm still of (at least) two minds about this, in that I'm fairly sure I prefer writing code from left to right but I'm also worried this won't fit in with other aspects of an APL-family language. BQN is an entirely different project than I is, and it's informed much more by APL than I. So I didn't so much switch to RtL as start over, and not switch back to LtR. I wrote about that in [this message](https://chat.stackexchange.com/transcript/52405?m=57926316#57926316) (lots more discussion above). + +## Considerations + +English text is read left to right. This in itself is not decisive in either direction: many contend that the way to read a function is first to read the function, then its argument. Although I usually read the other way, I do find that order to be useful sometimes. + +- Function application is pronounced "f of x", following the mathematical convention. +- Similarly, composition is pronounced "g of f" or "g compose f". The alternative "f then g", however, feels more natural to me. +- Transformation is nearly always given with the initial state first followed by the final state: "from rags to riches". Sometimes programmers use this convention as well: "png2jpg". + +Although mathematical functions are usually evaluated right-to-left, infix operations such as basic arithmetic are usually left-to-right. Of note is the fact that infinite series which start at zero and proceed upwards must be thought of as being evaluated in the positive direction, which is universally rendered as rightwards in number lines. + +- Function application is written function-first. +- Function composition is ordered right-to-left. +- Arrows indicating function types and in diagrams are written left-to-right. + +See page 147 of [this report](http://www.hpl.hp.com/techreports/Compaq-DEC/SRC-RR-169.pdf) for an interesting argument. + +As for programming precedent, stack-based languages such as Forth go from left to right. In Java-style object-oriented programming, methods go from left to right. This style of "method chaining" is particularly prevalent in Javascript. diff --git a/docs/commentary/ltr.html b/docs/commentary/ltr.html new file mode 100644 index 00000000..8ec5c892 --- /dev/null +++ b/docs/commentary/ltr.html @@ -0,0 +1,24 @@ +<head> + <link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/> + <link href="../style.css" rel="stylesheet"/> + <title>BQN: Left to right ordering?</title> +</head> +<div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">commentary</a></div> +<h1 id="left-to-right-ordering"><a class="header" href="#left-to-right-ordering">Left to right ordering?</a></h1> +<p>APL's right-to-left evaluation order is something many programmers ask about, and something I've questioned personally as well. In fact the first significant language I designed, called <a href="https://github.com/mlochbaum/ILanguage">I</a>, used a left to right ordering for all code.</p> +<p>I settled fairly quickly on sticking to the left to right ordering in BQN. I'm still of (at least) two minds about this, in that I'm fairly sure I prefer writing code from left to right but I'm also worried this won't fit in with other aspects of an APL-family language. BQN is an entirely different project than I is, and it's informed much more by APL than I. So I didn't so much switch to RtL as start over, and not switch back to LtR. I wrote about that in <a href="https://chat.stackexchange.com/transcript/52405?m=57926316#57926316">this message</a> (lots more discussion above).</p> +<h2 id="considerations"><a class="header" href="#considerations">Considerations</a></h2> +<p>English text is read left to right. This in itself is not decisive in either direction: many contend that the way to read a function is first to read the function, then its argument. Although I usually read the other way, I do find that order to be useful sometimes.</p> +<ul> +<li>Function application is pronounced "f of x", following the mathematical convention.</li> +<li>Similarly, composition is pronounced "g of f" or "g compose f". The alternative "f then g", however, feels more natural to me.</li> +<li>Transformation is nearly always given with the initial state first followed by the final state: "from rags to riches". Sometimes programmers use this convention as well: "png2jpg".</li> +</ul> +<p>Although mathematical functions are usually evaluated right-to-left, infix operations such as basic arithmetic are usually left-to-right. Of note is the fact that infinite series which start at zero and proceed upwards must be thought of as being evaluated in the positive direction, which is universally rendered as rightwards in number lines.</p> +<ul> +<li>Function application is written function-first.</li> +<li>Function composition is ordered right-to-left.</li> +<li>Arrows indicating function types and in diagrams are written left-to-right.</li> +</ul> +<p>See page 147 of <a href="http://www.hpl.hp.com/techreports/Compaq-DEC/SRC-RR-169.pdf">this report</a> for an interesting argument.</p> +<p>As for programming precedent, stack-based languages such as Forth go from left to right. In Java-style object-oriented programming, methods go from left to right. This style of "method chaining" is particularly prevalent in Javascript.</p> |
