diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-05-28 21:55:15 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-05-28 21:55:15 -0400 |
| commit | 18d1bce85de22f8bc7a08453618c7d9e94b61f92 (patch) | |
| tree | 87226d2fe5238c87079520db1a4f052740382f1c /docs | |
| parent | bd4209a653a68929a9fb1a215bbc3e34a393e753 (diff) | |
Editing
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/doc/hook.html | 12 | ||||
| -rw-r--r-- | docs/doc/identity.html | 15 |
2 files changed, 8 insertions, 19 deletions
diff --git a/docs/doc/hook.html b/docs/doc/hook.html index e300796a..a81c7b7d 100644 --- a/docs/doc/hook.html +++ b/docs/doc/hook.html @@ -102,7 +102,7 @@ </tbody> </table> <h2 id="description"><a class="header" href="#description">Description</a></h2> -<p>In the general case, I think of Before as using <code><span class='Function'>𝔽</span></code> as a preprocessing function applied to <code><span class='Value'>𝕨</span></code> (when there are two arguments) and After as using <code><span class='Function'>𝔾</span></code> as preprocessing for <code><span class='Value'>𝕩</span></code>. Then the other operand is called on the result and remaining argument. Here are some simple calls with Pair (<code><span class='Function'>⋈</span></code>): the result is a pair that corresponds to <code><span class='Value'>𝕨</span><span class='Ligature'>‿</span><span class='Value'>𝕩</span></code>, but one or the other result has been modified by the pointy-side function.</p> +<p>In the general case, I think of Before as using <code><span class='Function'>𝔽</span></code> as a preprocessing function applied to <code><span class='Value'>𝕨</span></code> (when there are two arguments), and After as using <code><span class='Function'>𝔾</span></code> as preprocessing for <code><span class='Value'>𝕩</span></code>. Then the other operand is called on the result and remaining argument. Here are some simple calls with <a href="pair.html">Pair</a> (<code><span class='Function'>⋈</span></code>): the result is a pair that corresponds to <code><span class='Value'>𝕨</span><span class='Ligature'>‿</span><span class='Value'>𝕩</span></code>, but one or the other result has been modified by the pointy-side function.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=OSDiiJriirjii4ggMgoKOSDii4jin5zihpUgMg==">↗️</a><pre> <span class='Number'>9</span> <span class='Function'>√</span><span class='Modifier2'>⊸</span><span class='Function'>⋈</span> <span class='Number'>2</span> ⟨ 3 2 ⟩ @@ -117,7 +117,7 @@ <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=e/Cdlak8MH3CqOKKuC8gNOKAv8KvMuKAvzHigL/CrzPigL/CrzM=">↗️</a><pre> <span class='Brace'>{</span><span class='Value'>𝕩</span><span class='Function'><</span><span class='Number'>0</span><span class='Brace'>}</span><span class='Modifier'>¨</span><span class='Modifier2'>⊸</span><span class='Function'>/</span> <span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>¯2</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>¯3</span><span class='Ligature'>‿</span><span class='Number'>¯3</span> ⟨ ¯2 ¯3 ¯3 ⟩ </pre> -<p>As <code><span class='Function'><</span></code> is a pervasive function, there's no need for the Each (<code><span class='Modifier'>¨</span></code>) in this case, and the clunky block function <code><span class='Brace'>{</span><span class='Value'>𝕩</span><span class='Function'><</span><span class='Number'>0</span><span class='Brace'>}</span></code> can also be written smaller with a combinator, as <code><span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>0</span></code>. More on that in the next section…</p> +<p>As <code><span class='Function'><</span></code> is a <a href="arithmetic.html#pervasion">pervasive</a> function, there's no need for the Each (<code><span class='Modifier'>¨</span></code>) in this case, and the clunky block function <code><span class='Brace'>{</span><span class='Value'>𝕩</span><span class='Function'><</span><span class='Number'>0</span><span class='Brace'>}</span></code> can also be written smaller with a combinator, as <code><span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>0</span></code>. More on that in the next section…</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=POKfnDDiirgvIDTigL/CrzLigL8x4oC/wq8z4oC/wq8z">↗️</a><pre> <span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>0</span><span class='Modifier2'>⊸</span><span class='Function'>/</span> <span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>¯2</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>¯3</span><span class='Ligature'>‿</span><span class='Number'>¯3</span> ⟨ ¯2 ¯3 ¯3 ⟩ </pre> @@ -126,7 +126,7 @@ <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=POKfnDAgIDTigL/CrzLigL8x4oC/wq8z4oC/wq8z">↗️</a><pre> <span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>0</span> <span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>¯2</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>¯3</span><span class='Ligature'>‿</span><span class='Number'>¯3</span> ⟨ 0 1 0 1 1 ⟩ </pre> -<p>If we expand <code><span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>0</span> <span class='Value'>x</span></code>, we get <code><span class='Value'>x</span> <span class='Function'><</span> <span class='Paren'>(</span><span class='Number'>0</span> <span class='Value'>x</span><span class='Paren'>)</span></code>, which doesn't quite make sense. That's because <code><span class='Number'>0</span></code> has a subject role, but <code><span class='Modifier2'>⟜</span></code> always applies its operands as functions. It's more accurate to use <code><span class='Value'>x</span> <span class='Function'><</span> <span class='Paren'>(</span><span class='Number'>0</span><span class='Brace'>{</span><span class='Function'>𝔽</span><span class='Brace'>}</span> <span class='Value'>x</span><span class='Paren'>)</span></code>, or just skip ahead to <code><span class='Value'>x</span> <span class='Function'><</span> <span class='Number'>0</span></code>.</p> +<p>If we expand <code><span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>0</span> <span class='Value'>x</span></code>, we get <code><span class='Value'>x</span> <span class='Function'><</span> <span class='Paren'>(</span><span class='Number'>0</span> <span class='Value'>x</span><span class='Paren'>)</span></code>, which doesn't quite make sense. That's because <code><span class='Number'>0</span></code> has a subject <a href="expression.html#syntactic-role">role</a>, but <code><span class='Modifier2'>⟜</span></code> always applies its operands as functions. It's more accurate to use <code><span class='Value'>x</span> <span class='Function'><</span> <span class='Paren'>(</span><span class='Number'>0</span><span class='Brace'>{</span><span class='Function'>𝔽</span><span class='Brace'>}</span> <span class='Value'>x</span><span class='Paren'>)</span></code>, or just skip ahead to <code><span class='Value'>x</span> <span class='Function'><</span> <span class='Number'>0</span></code>.</p> <p>Similar reasoning gives the following expansions:</p> <table> <thead> @@ -150,7 +150,7 @@ </tbody> </table> <p>Note that when there are two arguments, the constant "swallows" the one on the same side, so that the function is applied to the constant and the argument on the <em>opposite</em> side.</p> -<p>As in a train, if you want to use a function as a constant then you need to be explicity about it, with the <a href="constant.html">Constant</a> (<code><span class='Modifier'>˙</span></code>) modifier.</p> +<p>As in a train, if you want to use a function as a constant then you need to be explicit about it, with the <a href="constant.html">Constant</a> (<code><span class='Modifier'>˙</span></code>) modifier.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MyDii4jin5wo4oyKy5kp4oq44qWKICdhJyvihpUxMg==">↗️</a><pre> <span class='Number'>3</span> <span class='Function'>⋈</span><span class='Modifier2'>⟜</span><span class='Paren'>(</span><span class='Function'>⌊</span><span class='Modifier'>˙</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>⥊</span> <span class='String'>'a'</span><span class='Function'>+↕</span><span class='Number'>12</span> ┌─ ╵"abcd @@ -161,7 +161,7 @@ <p>In the more extreme case of wanting a <em>modifier</em> operand, you might try <code><span class='Function'>⋈</span><span class='Modifier2'>⟜</span><span class='Paren'>(</span><span class='Brace'>{</span><span class='Modifier2'>∘</span><span class='Brace'>}</span><span class='Modifier'>˙</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>⥊</span></code>, or <code><span class='Paren'>(</span><span class='Function'>⊣⋈</span><span class='Brace'>{</span><span class='Modifier2'>∘</span><span class='Brace'>}</span><span class='Modifier'>˙</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>⥊</span></code>, or just cheat with <code><span class='Function'>∾</span><span class='Modifier2'>⟜</span><span class='Bracket'>⟨</span><span class='Modifier2'>∘</span><span class='Bracket'>⟩</span><span class='Modifier2'>⊸</span><span class='Function'>⥊</span></code>.</p> <h2 id="combinations"><a class="header" href="#combinations">Combinations</a></h2> <p>If you like to go <a href="tacit.html">tacit</a>, you'll likely end up stringing together a few <code><span class='Modifier2'>⊸</span></code>s and <code><span class='Modifier2'>⟜</span></code>s at times. Of course the effects are entirely determined by the left-to-right precedence rule for modifiers, but it's interesting to examine what happens in more detail.</p> -<p>In the pattern <code><span class='Function'>F</span><span class='Modifier2'>⊸</span><span class='Function'>G</span><span class='Modifier2'>⟜</span><span class='Function'>H</span></code>, the ordering doesn't matter at all! That is, it means <code><span class='Paren'>(</span><span class='Function'>F</span><span class='Modifier2'>⊸</span><span class='Function'>G</span><span class='Paren'>)</span><span class='Modifier2'>⟜</span><span class='Function'>H</span></code>, but this is exactly the same function as <code><span class='Function'>F</span><span class='Modifier2'>⊸</span><span class='Paren'>(</span><span class='Function'>G</span><span class='Modifier2'>⟜</span><span class='Function'>H</span><span class='Paren'>)</span></code>. In both cases, <code><span class='Function'>F</span></code> is applied to <code><span class='Value'>𝕨</span></code>, <code><span class='Function'>H</span></code> is applied to <code><span class='Value'>𝕩</span></code>, and <code><span class='Function'>G</span></code> acts on both the results.</p> +<p>In the pattern <code><span class='Function'>F</span><span class='Modifier2'>⊸</span><span class='Function'>G</span><span class='Modifier2'>⟜</span><span class='Function'>H</span></code>, the ordering doesn't matter at all! That is, it means <code><span class='Paren'>(</span><span class='Function'>F</span><span class='Modifier2'>⊸</span><span class='Function'>G</span><span class='Paren'>)</span><span class='Modifier2'>⟜</span><span class='Function'>H</span></code>, but this is the same function as <code><span class='Function'>F</span><span class='Modifier2'>⊸</span><span class='Paren'>(</span><span class='Function'>G</span><span class='Modifier2'>⟜</span><span class='Function'>H</span><span class='Paren'>)</span></code>. In both cases, <code><span class='Function'>F</span></code> is applied to <code><span class='Value'>𝕨</span></code>, <code><span class='Function'>H</span></code> is applied to <code><span class='Value'>𝕩</span></code>, and <code><span class='Function'>G</span></code> acts on both the results (the parentheses do change whether <code><span class='Function'>F</span></code> or <code><span class='Function'>H</span></code> is called first, which only matters if they have side effects).</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=NCAt4oq44ouI4p+c4ouGIDI=">↗️</a><pre> <span class='Number'>4</span> <span class='Function'>-</span><span class='Modifier2'>⊸</span><span class='Function'>⋈</span><span class='Modifier2'>⟜</span><span class='Function'>⋆</span> <span class='Number'>2</span> ⟨ ¯4 7.38905609893065 ⟩ </pre> @@ -187,4 +187,4 @@ <span class='Paren'>(</span><span class='Function'>⌊≠÷</span><span class='Number'>2</span><span class='Modifier'>˙</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>⊑</span><span class='Modifier2'>⊸</span><span class='Function'>≤</span><span class='Modifier2'>⊸</span><span class='Function'>⊔</span> <span class='String'>"quicksort"</span> <span class='Comment'># Use to partition 𝕩 </span>⟨ "ic" "quksort" ⟩ </pre> -<p>Three is rare, but I use two <code><span class='Modifier2'>⊸</span></code>s all the time, as well as <code><span class='Modifier2'>⟜</span></code> followed by <code><span class='Modifier2'>⊸</span></code>, for example the <code><span class='Function'><</span><span class='Modifier2'>⟜</span><span class='String'>'a'</span><span class='Modifier2'>⊸</span><span class='Function'>/</span></code> filter on the <a href="../index.html">front page</a>. I think a combination like <code><span class='Value'>lots</span><span class='Modifier2'>∘</span><span class='Value'>of</span><span class='Modifier2'>○</span><span class='Value'>stuff</span><span class='Modifier2'>⊸</span><span class='Function'>/</span> <span class='Value'>x</span></code> reads very nicely when moving from left to right. When I see <code><span class='Modifier2'>⊸</span><span class='Function'>/</span></code> I know that I'm filtering <code><span class='Value'>x</span></code> and can read the rest with that context. The reason <code><span class='Modifier2'>⊸</span></code> that has all this power, but not <code><span class='Modifier2'>⟜</span></code>, has nothing to do with the modifiers themselves, as they're completely symmetrical. It's all in the way BQN defines modifier grammar, left to right.</p> +<p>Three is rare, but I use two <code><span class='Modifier2'>⊸</span></code>s all the time, as well as <code><span class='Modifier2'>⟜</span></code> followed by <code><span class='Modifier2'>⊸</span></code>, for example the <code><span class='Function'><</span><span class='Modifier2'>⟜</span><span class='String'>'a'</span><span class='Modifier2'>⊸</span><span class='Function'>/</span></code> filter on the <a href="../index.html">front page</a>. I think a combination like <code><span class='Value'>lots</span><span class='Modifier2'>∘</span><span class='Value'>of</span><span class='Modifier2'>○</span><span class='Value'>stuff</span><span class='Modifier2'>⊸</span><span class='Function'>/</span> <span class='Value'>x</span></code> reads very nicely when moving from right to left. When I see <code><span class='Modifier2'>⊸</span><span class='Function'>/</span></code> I know that I'm filtering <code><span class='Value'>x</span></code> and can read the rest with that context. The reason <code><span class='Modifier2'>⊸</span></code> has all this power, but not <code><span class='Modifier2'>⟜</span></code>, has nothing to do with the modifiers themselves, as they're completely symmetrical. It's all in the way BQN defines modifier grammar, left to right.</p> diff --git a/docs/doc/identity.html b/docs/doc/identity.html index 520e1657..5ef3bde7 100644 --- a/docs/doc/identity.html +++ b/docs/doc/identity.html @@ -18,7 +18,7 @@ <span class='String'>"left"</span> <span class='Function'>⊣</span> <span class='String'>"right"</span> "left" </pre> -<p>Depending on your past experiences, this could cause some confusion: built-in support for functions that do nothing? Documentation should say why a feature's there and how to use it, not just what it does, so we'll try to address this below. The most important single use is for tacit programming, but there are a variety of other uses as well.</p> +<p>Depending on your past experiences, this could cause some confusion: built-in support for functions that do nothing? Documentation should say why a feature's there and how to use it, not just what it does, so we'll try to address this below. The most important single use is for <a href="tacit.html">tacit</a> programming, but there are a variety of other uses as well.</p> <p>Of course, it's easy to write block functions <code><span class='Brace'>{</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code> and <code><span class='Brace'>{</span><span class='Value'>𝕨</span><span class='Brace'>}</span></code> that return particular arguments. While I would already make <code><span class='Function'>⊣</span></code> and <code><span class='Function'>⊢</span></code> primitives just because they are common and important, there are also specific disadvantages to using blocks. They fail to indicate that there are no side effects, as primitives would, and they also need special casing for the interpreter to manipulate them when applying <a href="undo.html">Undo</a> (<code><span class='Modifier'>⁼</span></code>) or making other inferences.</p> <h2 id="filling-arrays"><a class="header" href="#filling-arrays">Filling arrays</a></h2> <p>What's the easiest way to create a matrix with 0 on the first row, 1 on the second, and so on? Probably this one, with <a href="map.html#table">table</a>:</p> @@ -68,19 +68,8 @@ 4.5 </pre> <p>A larger class of block functions can be translated just by adding parentheses and <code><span class='Modifier'>˙</span></code> (there's a discussion of this technique in APL <a href="https://dfns.dyalog.com/n_tacit.htm">here</a>). It's helpful when writing tacit code to know that <code><span class='Function'>Fn</span><span class='Modifier2'>∘</span><span class='Function'>⊣</span></code> applies <code><span class='Function'>Fn</span></code> to the left argument only and <code><span class='Function'>Fn</span><span class='Modifier2'>∘</span><span class='Function'>⊢</span></code> applies it to the right argument—these can be read "Fn of left" and "Fn of right".</p> -<h2 id="syntax-tricks"><a class="header" href="#syntax-tricks">Syntax tricks</a></h2> +<h2 id="one-more-thing"><a class="header" href="#one-more-thing">One more thing</a></h2> <p>You've probably seen <code><span class='Function'>⊢</span></code> used in documentation to display the value of a variable being assigned. This is a hack, and in most contexts <code><span class='Function'>•Show</span></code> should be used to display values.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqiIGEg4oaQICJzaG93IHRoaXMi">↗️</a><pre> <span class='Function'>⊢</span> <span class='Value'>a</span> <span class='Gets'>←</span> <span class='String'>"show this"</span> "show this" </pre> -<p>More importantly, <code><span class='Modifier2'>∘</span><span class='Function'>⊣</span></code> can be used to ignore a right argument for modified assignment, to apply a function "in place" to a variable without writing the variable name twice.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YSDijL3iiJjiiqPihqkgQA==">↗️</a><pre> <span class='Value'>a</span> <span class='Function'>⌽</span><span class='Modifier2'>∘</span><span class='Function'>⊣</span><span class='Gets'>↩</span> <span class='String'>@</span> -"siht wohs" -</pre> -<p>In APL a tack can be used to avoid stranding numbers together. In BQN, stranding is explicit, and there's no need!</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=w7fin5wy4o2fM+KKoiAyNArDt+KfnDLijZ8zIDI0">↗️</a><pre> <span class='Function'>÷</span><span class='Modifier2'>⟜</span><span class='Number'>2</span><span class='Modifier2'>⍟</span><span class='Number'>3</span><span class='Function'>⊢</span> <span class='Number'>24</span> -3 - <span class='Function'>÷</span><span class='Modifier2'>⟜</span><span class='Number'>2</span><span class='Modifier2'>⍟</span><span class='Number'>3</span> <span class='Number'>24</span> -3 -</pre> -<p>(Wow, what a useless section.)</p> |
