diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-07-05 22:20:19 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-07-05 22:20:19 -0400 |
| commit | c96289046dbd42678c10d03ceb5734737392bf4c (patch) | |
| tree | fc897441ab6de8f5453aceb0424ff3969c696d4f /docs/doc | |
| parent | 3734638f2f04b5e298dca250f589ae1e4913f88f (diff) | |
Inter-documentation links and minor editing
Diffstat (limited to 'docs/doc')
| -rw-r--r-- | docs/doc/arithmetic.html | 6 | ||||
| -rw-r--r-- | docs/doc/based.html | 6 | ||||
| -rw-r--r-- | docs/doc/couple.html | 4 | ||||
| -rw-r--r-- | docs/doc/depth.html | 18 | ||||
| -rw-r--r-- | docs/doc/fold.html | 8 |
5 files changed, 21 insertions, 21 deletions
diff --git a/docs/doc/arithmetic.html b/docs/doc/arithmetic.html index 40a6067e..42bf677a 100644 --- a/docs/doc/arithmetic.html +++ b/docs/doc/arithmetic.html @@ -89,7 +89,7 @@ <span class='Function'>√</span> <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>4</span> ⟨ 0 1 1.4142135623730951 2 ⟩ </pre> -<p>Take note of the difference between the function <code><span class='Function'>-</span></code>, and the "high minus" character <code><span class='Number'>¯</span></code>, which is a part of numeric notation. Also shown is the number <code><span class='Number'>∞</span></code>, which BQN supports along with <code><span class='Number'>¯∞</span></code> (but depending on implementation BQN may or may not keep track of <code><span class='Number'>¯0</span></code>. Integer optimization loses the distinction so it's best not to rely on it).</p> +<p>Take note of the difference between the function <code><span class='Function'>-</span></code>, and the "high minus" character <code><span class='Number'>¯</span></code>, which is a part of <a href="syntax.html#constants">numeric notation</a>. Also shown is the number <code><span class='Number'>∞</span></code>, which BQN supports along with <code><span class='Number'>¯∞</span></code> (but depending on implementation BQN may or may not keep track of <code><span class='Number'>¯0</span></code>. Integer optimization loses the distinction so it's best not to rely on it).</p> <p>The logarithm is written with Undo: <code><span class='Function'>⋆</span><span class='Modifier'>⁼</span></code>. As with Power, the default base is <em>e</em>, giving a natural logarithm.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4ouG4oG8IDEwCgoyIOKLhuKBvCAxMDI0">↗️</a><pre> <span class='Function'>⋆</span><span class='Modifier'>⁼</span> <span class='Number'>10</span> 2.302585092994046 @@ -176,7 +176,7 @@ </tr> </tbody> </table> -<p>Now the monadic function symbols resemble those used in mathematics. In the case of Floor and Ceiling, this is because Ken Iverson invented them! As with other functions, he adapted them to work like other functions in order to create APL\360, in this case by removing the paired closing version of each one.</p> +<p>Now the monadic function symbols resemble those used in mathematics. In the case of Floor and Ceiling, this is because Ken Iverson invented them! As with other functions, he adapted them to use more uniform syntax in order to create APL\360, in this case by removing the paired closing version of each one.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oyKIM+ACgrijIggwq8wLjbigL8z4oC/My4wMQoKfCDCr+KInuKAv8KvNuKAvzDigL8y">↗️</a><pre> <span class='Function'>⌊</span> <span class='Number'>π</span> 3 @@ -276,7 +276,7 @@ <span class='Number'>¯∞</span><span class='Ligature'>‿</span><span class='Number'>π</span><span class='Ligature'>‿</span><span class='Number'>∞</span> <span class='Function'>≥</span> <span class='String'>@</span><span class='Ligature'>‿</span><span class='String'>'0'</span><span class='Ligature'>‿</span><span class='String'>'?'</span> ⟨ 0 0 0 ⟩ </pre> -<p>Equals and Not Equals are the two <em>equality</em> comparisons. Equals tests for <a href="match.html#atomic-equality">atomic equality</a> between each pair of atoms, as described in the Match documentation. Essentially, it returns <code><span class='Number'>1</span></code> only if the two values are indistinguishable to BQN and <code><span class='Number'>0</span></code> otherwise. Values of different types can never be equal, and characters are equal when they have the same code point.</p> +<p>Equals and Not Equals are the two <em>equality</em> comparisons. Equals tests for atomic equality between each pair of atoms, as <a href="match.html#atomic-equality">described</a> in the Match documentation. Essentially, it returns <code><span class='Number'>1</span></code> only if the two values are indistinguishable to BQN and <code><span class='Number'>0</span></code> otherwise. Values of different types can never be equal, and characters are equal when they have the same code point.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=K+KAvy3igL/Dl+KAv8O3ID0g4oqR4p+oLeKfqQoKJ2InIOKJoCAiYWJhY2JhIg==">↗️</a><pre> <span class='Function'>+</span><span class='Ligature'>‿</span><span class='Function'>-</span><span class='Ligature'>‿</span><span class='Function'>×</span><span class='Ligature'>‿</span><span class='Function'>÷</span> <span class='Function'>=</span> <span class='Function'>⊑</span><span class='Bracket'>⟨</span><span class='Function'>-</span><span class='Bracket'>⟩</span> ⟨ 0 1 0 0 ⟩ diff --git a/docs/doc/based.html b/docs/doc/based.html index 23278025..e865ad4b 100644 --- a/docs/doc/based.html +++ b/docs/doc/based.html @@ -9,8 +9,8 @@ <p>This page explains how BQN's array model (christened "based" <a href="https://dl.acm.org/doi/abs/10.1145/586656.586663">in 1981</a>) differs from the models used by existing APL dialects, and why the choice was made to discard APL's "everything is an array" dictum. If you're not wondering what the difference is, and don't think everything should be an array, then you can probably just read about BQN's <a href="types.html">type system</a> instead.</p> <p>If you're an array programmer then I have bad news for you. My thesis here is that APL took a wrong turn around 1981 when it extrapolated the excellent, but limited, flat array model of APL\360 to the ill-founded nested array model and the rigorous but clumsy boxed array model. Make that two wrong turns, I guess. Simultaneously. Anyway, if you've been brought up in either of these array models, then the best thing to do when starting BQN is to throw out your existing ideas about array depth and nesting (but don't worry too much: the fundamental concept of an array as a rectangular collection of data still holds!). If you'd like to ponder the relationship of BQN to APL later, that's great, but trying to initially understand BQN in terms of APL or J will just cause confusion.</p> <h2 id="starting-from-atoms">Starting from atoms</h2> -<p>APL tends to define its data by starting with the array and then looking downwards in depth at what it contains. The based array model, as the name suggests, starts at the foundations, which in BQN are called "atoms". There are five types of atom, which together with the array type give the six types a value can have in BQN. Based means being yourself, and an atom's <em>not</em> an array.</p> -<p>An atom has <a href="depth.html">depth</a> 0, and doesn't inherently have a shape. However, primitives that expect an array promote atoms by <a href="enclose.html">enclosing</a> them to get a rank-0, or <em>unit</em>, array that contains the atom (any value can be enclosed in this way, giving a unit array with higher depth, but it only happens automatically for atoms). Rank and shape both do this, so an atom can be considered to have the same dimensions as a unit array: rank 0 and shape <code><span class='Bracket'>⟨⟩</span></code>. An atom is also considered a kind of unit, but it's not a unit array.</p> +<p>APL tends to define its data by starting with the array and then looking downwards in depth at what it contains. The based array model, as the name suggests, starts at the foundations, which in BQN are called "atoms". There are six <a href="types.html">types</a> of atom, which together with the array type give the seven types a value can have in BQN. Based means being yourself, and an atom's <em>not</em> an array.</p> +<p>An atom has <a href="depth.html">depth</a> 0, and doesn't inherently have a shape. However, primitives that expect an array promote atoms by <a href="enclose.html">enclosing</a> them to get a rank-0, or <em>unit</em>, array that contains the atom (any value can be enclosed in this way, giving a unit array with higher depth, but it only happens automatically for atoms). <a href="shape.html">Rank and shape</a> both do this, so an atom can be considered to have the same dimensions as a unit array: rank 0 and shape <code><span class='Bracket'>⟨⟩</span></code>. An atom is also considered a kind of unit, but it's not a unit array.</p> <p>Atoms are displayed as plain values, while enclosed atoms, that is, depth-1 unit arrays, are shown with an array display.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MyAgICAjIEF0b20KPDMgICAjIEFycmF5CiczJyAgIyBBdG9t">↗️</a><pre> <span class='Number'>3</span> <span class='Comment'># Atom </span>3 @@ -26,7 +26,7 @@ <span class='Function'>≡</span> <span class='Value'>plus</span> 0 </pre> -<p>The primitives that return a single number, like Rank (<code><span class='Function'>=</span></code>), Length (<code><span class='Function'>≠</span></code>), and Match (<code><span class='Function'>≡</span></code>), give it as an atom, not an array.</p> +<p>The primitives that return a single number, like Rank (<code><span class='Function'>=</span></code>), Length (<code><span class='Function'>≠</span></code>), and <a href="match.html">Match</a> (<code><span class='Function'>≡</span></code>), give it as an atom, not an array.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omhICJhYmMiCuKJoSDiiaEgImFiYyIgICMgVGhlIHJlc3VsdCB3YXMgYW4gYXRvbQ==">↗️</a><pre> <span class='Function'>≡</span> <span class='String'>"abc"</span> 1 <span class='Function'>≡</span> <span class='Function'>≡</span> <span class='String'>"abc"</span> <span class='Comment'># The result was an atom diff --git a/docs/doc/couple.html b/docs/doc/couple.html index fa9b905a..1e55a233 100644 --- a/docs/doc/couple.html +++ b/docs/doc/couple.html @@ -65,7 +65,7 @@ <span class='Function'>∾</span> <span class='Function'>⥊</span> <span class='Function'>⥊</span><span class='Modifier'>¨</span> <span class='Value'>a</span> "ABrstABuvwABxyzCDrstCDuvwCDxyz" </pre> -<p>The way this happens, and the constraint that all inner arrays have the same shape, is closely connected to the concept of an array, and like Table <code><span class='Modifier'>⌜</span></code>, Merge might be considered a fundamental way to build up multidimensional arrays from lists. In both cases rank-0 or unit arrays are somewhat special. They are the identity element of a function with Table, and can be produced by Merge inverse, <code><span class='Function'>></span><span class='Modifier'>⁼</span></code> <strong>on a list</strong>, which forces either the outer or inner shape to be empty (BQN chooses <code><span class='Function'>></span><span class='Modifier'>⁼</span></code> to be <code><span class='Function'><</span></code>, but only on an array, as <code><span class='Function'>></span></code> cannot produce non-arrays). Merge has another catch as well: it cannot produce arrays with a <code><span class='Number'>0</span></code> in the shape, except at the end, without some sort of prototype system.</p> +<p>The way this happens, and the constraint that all inner arrays have the same shape, is closely connected to the concept of an array, and like <a href="map.html#table">Table</a> <code><span class='Modifier'>⌜</span></code>, Merge might be considered a fundamental way to build up multidimensional arrays from lists. In both cases rank-0 or <a href="enclose.html#whats-a-unit">unit</a> arrays are somewhat special. They are the <a href="fold.html#identity-values">identity value</a> of a function with Table, and can be produced by Merge inverse, <code><span class='Function'>></span><span class='Modifier'>⁼</span></code> <strong>on a list</strong>, which forces either the outer or inner shape to be empty (BQN chooses <code><span class='Function'>></span><span class='Modifier'>⁼</span></code> to be <code><span class='Function'><</span></code>, but only on an array, as <code><span class='Function'>></span></code> cannot produce non-arrays). Merge has another catch as well: it cannot produce arrays with a <code><span class='Number'>0</span></code> in the shape, except at the end, unless fills can be specified.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqiIGUg4oaQIOKfqOKfqcKoIOKGlTMK4omiID4gZQriiaIgPiA+IGU=">↗️</a><pre> <span class='Function'>⊢</span> <span class='Value'>e</span> <span class='Gets'>←</span> <span class='Bracket'>⟨⟩</span><span class='Modifier'>¨</span> <span class='Function'>↕</span><span class='Number'>3</span> ⟨ ⟨⟩ ⟨⟩ ⟨⟩ ⟩ <span class='Function'>≢</span> <span class='Function'>></span> <span class='Value'>e</span> @@ -75,7 +75,7 @@ </pre> <p>Above we start with a list of three empty arrays. After merging once we get a shape <code><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>0</span></code> array, sure, but what happens next? The shape added by another merge is the shared shape of that array's elements—and there aren't any! If the nested list kept some type information around then we might know, but extra type information is essentially how lists pretend to be arrays. True dynamic lists simply can't represent multidimensional arrays with a <code><span class='Number'>0</span></code> in the middle of the shape. In this sense, arrays are a richer model than nested lists.</p> <h2 id="coupling-units">Coupling units</h2> -<p>A note on the topic of Solo and Couple applied to units. As always, one axis will be added, so that the result is a list (strangely, J's <a href="https://code.jsoftware.com/wiki/Vocabulary/commaco#dyadic">laminate</a> differs from Couple in this one case, as it will add an axis to get a shape <code><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>1</span></code> result). For Solo, this is interchangeable with Deshape (<code><span class='Function'>⥊</span></code>), and either primitive might be chosen for stylistic reasons. For Couple, it is equivalent to Join-to (<code><span class='Function'>∾</span></code>), but this is an irregular form of Join-to because it is the only case where Join-to adds an axis to both arguments instead of just one. Couple should be preferred in this case.</p> +<p>A note on the topic of Solo and Couple applied to units. As always, one axis will be added, so that the result is a list (strangely, J's <a href="https://code.jsoftware.com/wiki/Vocabulary/commaco#dyadic">laminate</a> differs from Couple in this one case, as it will add an axis to get a shape <code><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>1</span></code> result). For Solo, this is interchangeable with <a href="reshape.html">Deshape</a> (<code><span class='Function'>⥊</span></code>), and either primitive might be chosen for stylistic reasons. For Couple, it is equivalent to <a href="join.html">Join-to</a> (<code><span class='Function'>∾</span></code>), but this is an irregular form of Join-to because it is the only case where Join-to adds an axis to both arguments instead of just one. Couple should be preferred in this case.</p> <p>The pair function, which creates a list from its arguments, can be written <code><span class='Function'>Pair</span> <span class='Gets'>←</span> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'><</span></code>, while <code><span class='Function'>≍</span></code> in either valence is <code><span class='Function'>></span><span class='Modifier2'>∘</span><span class='Function'>Pair</span></code>. As an interesting consequence, <code><span class='Function'>≍</span> <span class='Gets'>←→</span> <span class='Function'>></span><span class='Modifier2'>∘</span><span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'><</span></code>, and the same relationship holds for <code><span class='Function'>Pair</span></code>.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oMiwz4p+pIOKJjeKXizwgImFiYyIgICMgUGFpciB0d28gdmFsdWVzCuKJjeKXizwgImFiYyIgICAgICAgICMgUGFpciBvbmUoPykgdmFsdWU=">↗️</a><pre> <span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Number'>3</span><span class='Bracket'>⟩</span> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'><</span> <span class='String'>"abc"</span> <span class='Comment'># Pair two values </span>⟨ ⟨ 2 3 ⟩ "abc" ⟩ diff --git a/docs/doc/depth.html b/docs/doc/depth.html index 2332c674..4c5ca982 100644 --- a/docs/doc/depth.html +++ b/docs/doc/depth.html @@ -72,7 +72,7 @@ <span class='Function'>≡</span> <span class='String'>"a string is a list of characters"</span> 1 </pre> -<p>Depth is somewhat analogous to an array's rank <code><span class='Function'>=</span><span class='Value'>𝕩</span></code>, and in fact rank can be "converted" to depth by splitting rows with <code><span class='Function'><</span><span class='Modifier2'>⎉</span><span class='Number'>1</span></code>, reducing the rank by 1 and increasing the depth. Unlike rank, Depth doesn't care at all about its argument's shape:</p> +<p>Depth is somewhat analogous to an array's <a href="shape.html">rank</a> <code><span class='Function'>=</span><span class='Value'>𝕩</span></code>, and in fact rank can be "converted" to depth by splitting rows with <code><span class='Function'><</span><span class='Modifier2'>⎉</span><span class='Number'>1</span></code>, reducing the rank by 1 and increasing the depth. Unlike rank, Depth doesn't care at all about its argument's shape:</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omhIDPigL804qWKImNoYXJhY3RlcnMiCuKJoSAoMSvihpUxMCnipYoiY2hhcmFjdGVycyI=">↗️</a><pre> <span class='Function'>≡</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span><span class='Function'>⥊</span><span class='String'>"characters"</span> 1 <span class='Function'>≡</span> <span class='Paren'>(</span><span class='Number'>1</span><span class='Function'>+↕</span><span class='Number'>10</span><span class='Paren'>)</span><span class='Function'>⥊</span><span class='String'>"characters"</span> @@ -125,13 +125,13 @@ </tr> </tbody> </table> -<p>Functions such as Take and Drop use a single number per axis. When the left argument is a list of numbers, they apply to initial axes. But for convenience, a single number is also accepted, and applied to the first axis only. This is equivalent to ravelling the left argument before applying the function.</p> +<p>Functions such as <a href="take.html">Take and Drop</a> use a single number per axis. When the left argument is a list of numbers, they apply to initial axes. But for convenience, a single number is also accepted, and applied to the first axis only. This is equivalent to <a href="reshape.html">deshaping</a> the left argument before applying the function.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omiMuKGkTfigL834oC/N+KAvzfipYoiYWJjIgriiaIy4oC/MeKAvzHihpE34oC/N+KAvzfigL834qWKImFiYyI=">↗️</a><pre> <span class='Function'>≢</span><span class='Number'>2</span><span class='Function'>↑</span><span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Function'>⥊</span><span class='String'>"abc"</span> ⟨ 2 7 7 7 ⟩ <span class='Function'>≢</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Function'>↑</span><span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Function'>⥊</span><span class='String'>"abc"</span> ⟨ 2 1 1 7 ⟩ </pre> -<p>In these cases the flexibility seems trivial because the left argument has depth 1 or 0: it is an array or isn't, and it's obvious what a plain number should do. But for the second row in the table, the left argument is always an array. The general case is that the left argument is a vector and its elements correspond to right argument axes:</p> +<p>In these cases the flexibility seems trivial because the left argument has depth 1 or 0: it is an array or isn't, and it's obvious what a plain number should do. But for the second row in the table, the left argument is always an array. The general case (<a href="select.html">Select</a> below) is that the left argument is a list and its elements correspond to right argument axes:</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oM+KAvzIsMeKAvzTigL8x4p+pIOKKjyDihpU24oC/Nw==">↗️</a><pre> <span class='Bracket'>⟨</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Bracket'>⟩</span> <span class='Function'>⊏</span> <span class='Function'>↕</span><span class='Number'>6</span><span class='Ligature'>‿</span><span class='Number'>7</span> ┌─ ╵ ⟨ 3 1 ⟩ ⟨ 3 4 ⟩ ⟨ 3 1 ⟩ @@ -142,7 +142,7 @@ <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oM+KAvzIsMeKfqSA84o2fKDA94omhKcKo4oq44oqPIOKGlTbigL83">↗️</a><pre> <span class='Bracket'>⟨</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Number'>1</span><span class='Bracket'>⟩</span> <span class='Function'><</span><span class='Modifier2'>⍟</span><span class='Paren'>(</span><span class='Number'>0</span><span class='Function'>=≡</span><span class='Paren'>)</span><span class='Modifier'>¨</span><span class='Modifier2'>⊸</span><span class='Function'>⊏</span> <span class='Function'>↕</span><span class='Number'>6</span><span class='Ligature'>‿</span><span class='Number'>7</span> ⟨ ⟨ 3 1 ⟩ ⟨ 2 1 ⟩ ⟩ </pre> -<p>While very consistent, this extension represents a small convenience and makes it difficult to act on a single axis, which for Replicate and <a href="group.html">Group</a> is probably the most common way the primitive is used:</p> +<p>While very consistent, this extension represents a small convenience and makes it difficult to act on a single axis, which for <a href="replicate.html">Replicate</a> and <a href="group.html">Group</a> is probably the most common way the primitive is used:</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=M+KAvzLigL8x4oC/MuKAvzMgLyAiYWJjZGUi">↗️</a><pre> <span class='Number'>3</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'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span> <span class='Function'>/</span> <span class='String'>"abcde"</span> "aaabbcddeee" </pre> @@ -152,7 +152,7 @@ ⟨ ⟨ 2 1 4 0 ⟩ ⟨ 2 1 4 1 ⟩ ⟩ </pre> <h2 id="the-depth-modifier">The Depth modifier</h2> -<p>The Depth 2-modifier (<code><span class='Modifier2'>⚇</span></code>) is a generalization of Each that allows diving deeper into an array. To illustrate it we'll use a shape <code><span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>3</span></code> array of lists of lists.</p> +<p>The Depth 2-modifier (<code><span class='Modifier2'>⚇</span></code>) is a generalization of <a href="map.html">Each</a> that allows diving deeper into an array. To illustrate it we'll use a shape <code><span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>3</span></code> array of lists of lists.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqiIG4g4oaQIDzijokx4o2fMiA04oC/M+KAvzLigL8y4qWK4oaVNDgK4omhIG4=">↗️</a><pre> <span class='Function'>⊢</span> <span class='Value'>n</span> <span class='Gets'>←</span> <span class='Function'><</span><span class='Modifier2'>⎉</span><span class='Number'>1</span><span class='Modifier2'>⍟</span><span class='Number'>2</span> <span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Function'>⥊↕</span><span class='Number'>48</span> ┌─ ╵ ⟨ ⟨ 0 1 ⟩ ⟨ 2 3 ⟩ ⟩ ⟨ ⟨ 4 5 ⟩ ⟨ 6 7 ⟩ ⟩ ⟨ ⟨ 8 9 ⟩ ⟨ 10 11 ⟩ ⟩ @@ -163,7 +163,7 @@ <span class='Function'>≡</span> <span class='Value'>n</span> 3 </pre> -<p>Reversing n swaps all the rows:</p> +<p>Reversing <code><span class='Value'>n</span></code> swaps all the rows:</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oy9IG4=">↗️</a><pre> <span class='Function'>⌽</span> <span class='Value'>n</span> ┌─ ╵ ⟨ ⟨ 36 37 ⟩ ⟨ 38 39 ⟩ ⟩ ⟨ ⟨ 40 41 ⟩ ⟨ 42 43 ⟩ ⟩ ⟨ ⟨ 44 45 ⟩ ⟨ 46 47 ⟩ ⟩ @@ -172,7 +172,7 @@ ⟨ ⟨ 0 1 ⟩ ⟨ 2 3 ⟩ ⟩ ⟨ ⟨ 4 5 ⟩ ⟨ 6 7 ⟩ ⟩ ⟨ ⟨ 8 9 ⟩ ⟨ 10 11 ⟩ ⟩ ┘ </pre> -<p>Depth <code><span class='Number'>¯1</span></code> is equivalent to Each, and reverses the larger vectors, while depth <code><span class='Number'>¯2</span></code> applies Each twice to reverse the smaller vectors:</p> +<p>Depth <code><span class='Number'>¯1</span></code> is equivalent to Each, and reverses the larger lists, while depth <code><span class='Number'>¯2</span></code> applies Each twice to reverse the smaller lists:</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oy94pqHwq8xIG4K4oy94pqHwq8yIG4=">↗️</a><pre> <span class='Function'>⌽</span><span class='Modifier2'>⚇</span><span class='Number'>¯1</span> <span class='Value'>n</span> ┌─ ╵ ⟨ ⟨ 2 3 ⟩ ⟨ 0 1 ⟩ ⟩ ⟨ ⟨ 6 7 ⟩ ⟨ 4 5 ⟩ ⟩ ⟨ ⟨ 10 11 ⟩ ⟨ 8 9 ⟩ ⟩ @@ -188,13 +188,13 @@ ⟨ ⟨ 37 36 ⟩ ⟨ 39 38 ⟩ ⟩ ⟨ ⟨ 41 40 ⟩ ⟨ 43 42 ⟩ ⟩ ⟨ ⟨ 45 44 ⟩ ⟨ 47 46 ⟩ ⟩ ┘ </pre> -<p>While a negative depth tells how many levels to go down, a non-negative depth gives the maximum depth of the argument before applying the left operand. On a depth-3 array like above, depth <code><span class='Number'>2</span></code> is equivalent to <code><span class='Number'>¯1</span></code> and depth <code><span class='Number'>1</span></code> is equivalent to <code><span class='Number'>¯2</span></code>. A depth of <code><span class='Number'>0</span></code> means to descend all the way to the level of atoms, that is, apply <a href="https://aplwiki.com/wiki/Pervasion">pervasively</a>, like an arithmetic function.</p> +<p>While a negative depth tells how many levels to go down, a non-negative depth gives the maximum depth of the argument before applying the left operand. On a depth-3 array like above, depth <code><span class='Number'>2</span></code> is equivalent to <code><span class='Number'>¯1</span></code> and depth <code><span class='Number'>1</span></code> is equivalent to <code><span class='Number'>¯2</span></code>. A depth of <code><span class='Number'>0</span></code> means to descend all the way to the level of atoms, that is, apply <a href="arithmetic.html#pervasion">pervasively</a>, like an arithmetic function.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oJ2EnLCJiYyLin6kg4omN4pqHMCDin6gy4oC/Myw04p+p">↗️</a><pre> <span class='Bracket'>⟨</span><span class='String'>'a'</span><span class='Separator'>,</span><span class='String'>"bc"</span><span class='Bracket'>⟩</span> <span class='Function'>≍</span><span class='Modifier2'>⚇</span><span class='Number'>0</span> <span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Separator'>,</span><span class='Number'>4</span><span class='Bracket'>⟩</span> ┌─ · ⟨ ⟨ 'a' 2 ⟩ ⟨ 'a' 3 ⟩ ⟩ ⟨ ⟨ 'b' 4 ⟩ ⟨ 'c' 4 ⟩ ⟩ ┘ </pre> -<p>With a positive operand, Depth doesn't have to use the same depth everywhere. Here, Length is applied as soon as the depth for a particular element is 1 or less, including if the argument has depth 0. For example, it maps over <code><span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='Number'>3</span><span class='Separator'>,</span><span class='Number'>4</span><span class='Bracket'>⟩⟩</span></code>, but not over <code><span class='Bracket'>⟨</span><span class='Number'>11</span><span class='Separator'>,</span><span class='Number'>12</span><span class='Bracket'>⟩</span></code>, even though these are elements of the same array.</p> +<p>With a positive operand, Depth doesn't have to use the same depth everywhere. Here, <a href="shape.html">Length</a> is applied as soon as the depth for a particular element is 1 or less, including if the argument has depth 0. For example, it maps over <code><span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='Number'>3</span><span class='Separator'>,</span><span class='Number'>4</span><span class='Bracket'>⟩⟩</span></code>, but not over <code><span class='Bracket'>⟨</span><span class='Number'>11</span><span class='Separator'>,</span><span class='Number'>12</span><span class='Bracket'>⟩</span></code>, even though these are elements of the same array.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omg4pqHMSDin6gxLOKfqDIs4p+oMyw04p+p4p+pLOKfqDUs4p+oNiw34p+pLOKfqDgsOSwxMOKfqeKfqSzin6gxMSwxMuKfqeKfqQ==">↗️</a><pre> <span class='Function'>≠</span><span class='Modifier2'>⚇</span><span class='Number'>1</span> <span class='Bracket'>⟨</span><span class='Number'>1</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='Number'>3</span><span class='Separator'>,</span><span class='Number'>4</span><span class='Bracket'>⟩⟩</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='Number'>5</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='Number'>6</span><span class='Separator'>,</span><span class='Number'>7</span><span class='Bracket'>⟩</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='Number'>8</span><span class='Separator'>,</span><span class='Number'>9</span><span class='Separator'>,</span><span class='Number'>10</span><span class='Bracket'>⟩⟩</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='Number'>11</span><span class='Separator'>,</span><span class='Number'>12</span><span class='Bracket'>⟩⟩</span> ⟨ 1 ⟨ 1 2 ⟩ ⟨ 1 2 3 ⟩ 2 ⟩ </pre> diff --git a/docs/doc/fold.html b/docs/doc/fold.html index 7c03d174..7c2703c8 100644 --- a/docs/doc/fold.html +++ b/docs/doc/fold.html @@ -69,7 +69,7 @@ <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=IcK0IOKfqOKOiuKfqQ==">↗️</a><pre> <span class='Function'>!</span><span class='Modifier'>´</span> <span class='Bracket'>⟨</span><span class='Modifier2'>⎊</span><span class='Bracket'>⟩</span> ⎊ </pre> -<p>Folding over a list of two values applies <code><span class='Function'>𝔽</span></code> once, since <code><span class='Function'>𝔽</span></code> is always called on two arguments. But what about zero values? Should <code><span class='Function'>𝔽</span></code> be applied minus one times? Sort of. BQN checks to see if it knows an <em>identity value</em> for the operand function, and returns that, never calling the function. This works for the arithmetic functions we showed above, always returning a single number.</p> +<p>Folding over a list of two values applies <code><span class='Function'>𝔽</span></code> once, since <code><span class='Function'>𝔽</span></code> is always called on two arguments. But what about zero values? Should <code><span class='Function'>𝔽</span></code> be applied minus one times? Sort of. BQN checks to see if it knows an <em>identity value</em> for the operand function, and returns that, never calling the function. This works for the <a href="arithmetic.html">arithmetic functions</a> we showed above, always returning a single number.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=K8K0IOKfqOKfqSAgIyBBZGQgbm90aGluZyB1cCwgZ2V0IHplcm8K4oyIwrQg4p+o4p+pICAjIFRoZSBzbWFsbGVzdCBudW1iZXIK4oinwrQg4p+o4p+pICAjIEFsbCB0aGUgZWxlbWVudHMgaW4gdGhlIGxpc3QgYXJlIHRydWXigKY=">↗️</a><pre> <span class='Function'>+</span><span class='Modifier'>´</span> <span class='Bracket'>⟨⟩</span> <span class='Comment'># Add nothing up, get zero </span>0 <span class='Function'>⌈</span><span class='Modifier'>´</span> <span class='Bracket'>⟨⟩</span> <span class='Comment'># The smallest number @@ -133,15 +133,15 @@ </tbody> </table> <h3 id="right-to-left">Right-to-left</h3> -<p>The functions we've shown so far are associative (ignoring floating point imprecision), meaning it's equally valid to combine elements of the argument list in any order. But it can be useful to fold using a non-associative function. In this case you must know that Fold performs a <em>right fold</em>, starting from the array and working towards the beginning.</p> +<p>The functions we've shown so far are associative (ignoring floating point imprecision), meaning it's equally valid to combine elements of the argument list in any order. But it can be useful to fold using a non-associative function. In this case you must know that Fold performs a <em>right fold</em>, starting from the end of the array and working towards the beginning.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omN4peLPMK0ICJhYmNkIgoKJ2EnIOKJjeKXizwgJ2InIOKJjeKXizwgJ2MnIOKJjeKXizwgJ2QnICAjIEV4cGFuZGVkIGZvcm0=">↗️</a><pre> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'><</span><span class='Modifier'>´</span> <span class='String'>"abcd"</span> ⟨ 'a' ⟨ 'b' "cd" ⟩ ⟩ <span class='String'>'a'</span> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'><</span> <span class='String'>'b'</span> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'><</span> <span class='String'>'c'</span> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'><</span> <span class='String'>'d'</span> <span class='Comment'># Expanded form </span>⟨ 'a' ⟨ 'b' "cd" ⟩ ⟩ </pre> -<p>Using the pair function <code><span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'><</span></code> as an operand shows the structure nicely. This fold first pairs the final two characters <code><span class='String'>'c'</span></code> and <code><span class='String'>'d'</span></code>, then pairs <code><span class='String'>'b'</span></code> with that and so on. This matches BQN's right-to-left order of evaluation. More declaratively we might say that each character is paired with the result of folding over everything to its right.</p> -<p>BQN doesn't provide a left Fold (<code><span class='Modifier'>`</span></code> is Scan). However, you can fold from the left by reversing (<code><span class='Function'>⌽</span></code>) the argument list and also reversing (<code><span class='Modifier'>˜</span></code>) the operand function's argument order.</p> +<p>Using the <a href="couple.html#coupling-units">pair</a> function <code><span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'><</span></code> as an operand shows the structure nicely. This fold first pairs the final two characters <code><span class='String'>'c'</span></code> and <code><span class='String'>'d'</span></code>, then pairs <code><span class='String'>'b'</span></code> with that and so on. This matches BQN's right-to-left order of evaluation. More declaratively we might say that each character is paired with the result of folding over everything to its right.</p> +<p>BQN doesn't provide a left Fold (<code><span class='Modifier'>`</span></code> is <a href="scan.html">Scan</a>). However, you can fold from the left by <a href="reverse.html#reverse">reversing</a> (<code><span class='Function'>⌽</span></code>) the argument list and also reversing (<code><span class='Modifier'>˜</span></code>) the operand function's argument order.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omN4peLPMucwrQg4oy9ICJhYmNkIg==">↗️</a><pre> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'><</span><span class='Modifier'>˜´</span> <span class='Function'>⌽</span> <span class='String'>"abcd"</span> ⟨ ⟨ "ab" 'c' ⟩ 'd' ⟩ </pre> |
