aboutsummaryrefslogtreecommitdiff
path: root/docs/doc/enclose.html
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2022-06-29 22:38:29 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2022-06-29 22:39:07 -0400
commit47c0a52e614d01eb251da9301c2961338141ab6c (patch)
treed0ac94596d81b2680b09fb7abc924fec1ca10a50 /docs/doc/enclose.html
parenta18eadf8df214b52ebb90c9bbbc433a3ad7c6ced (diff)
Editing continues, with some deletions this time
Diffstat (limited to 'docs/doc/enclose.html')
-rw-r--r--docs/doc/enclose.html20
1 files changed, 10 insertions, 10 deletions
diff --git a/docs/doc/enclose.html b/docs/doc/enclose.html
index e00d168b..5d117405 100644
--- a/docs/doc/enclose.html
+++ b/docs/doc/enclose.html
@@ -5,7 +5,7 @@
</head>
<div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">doc</a></div>
<h1 id="enclose"><a class="header" href="#enclose">Enclose</a></h1>
-<p>The function enclose creates a unit array whose only element is <code><span class='Value'>𝕩</span></code>.</p>
+<p>The function Enclose creates a unit array whose only element is <code><span class='Value'>𝕩</span></code>.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=PCAieHl6Ig==">↗️</a><pre> <span class='Function'>&lt;</span> <span class='String'>&quot;xyz&quot;</span>
┌·
· "xyz"
@@ -22,7 +22,7 @@
</pre>
<p>If there are no axes, what use is an array? Rank 0 certainly qualifies as an edge case, as there's no rank -1 below it. Most often when a unit array is used it's because there <em>are</em> relevant axes, but we want an array that doesn't include them (sound cryptic? Just keep reading…).</p>
<p>This contrasts with an atom like <code><span class='Number'>137</span></code>, which is considered a unit but not a unit <em>array</em>. An atom has no axes just because it doesn't have axes. But because it has no axes, it has the same shape <code><span class='Bracket'>⟨⟩</span></code> as a unit array, by convention.</p>
-<p>Some unit arrays are made by removing an axis from an existing array. First Cell (<code><span class='Function'>⊏</span></code>) or <a href="fold.html">Insert</a> (<code><span class='Modifier'>˝</span></code>) might do this:</p>
+<p>Some unit arrays are made by removing an axis from an existing array. <a href="select.html#first-cell">First Cell</a> (<code><span class='Function'>⊏</span></code>) or <a href="fold.html">Insert</a> (<code><span class='Modifier'>˝</span></code>) might do this:</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=bCDihpAgMuKAvzfigL8x4oC/OOKAvzLigL84CuKKjyBsCivLnSBs">↗️</a><pre> <span class='Value'>l</span> <span class='Gets'>←</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>7</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>8</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>8</span>
<span class='Function'>⊏</span> <span class='Value'>l</span>
┌·
@@ -37,11 +37,11 @@
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=K8udy5ggM+KAvzTipYrihpUxMg==">↗️</a><pre> <span class='Function'>+</span><span class='Modifier'>˝˘</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span><span class='Function'>⥊↕</span><span class='Number'>12</span>
⟨ 6 22 38 ⟩
</pre>
-<p>In this case each call to <code><span class='Function'>+</span><span class='Modifier'>˝</span></code> returns a cell of the result. The result is a list, so its cells are units! Here, <a href="rank.html">Cells</a> (<code><span class='Modifier'>˘</span></code>) &quot;hides&quot; one axis from its operand, and the operand <code><span class='Function'>+</span><span class='Modifier'>˝</span></code> reduces out an axis, leaving zero axes—until Cells assembles the results, putting its axis back. In this case, <code><span class='Function'>+</span><span class='Modifier'>´</span></code> would also be tolerated. But it's wrong, because each result really should be a zero-axis array. We can reveal this by making an array whose elements aren't atoms.</p>
-<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=K8K0y5gg4p+o4oaVMiwiYWIi4p+p4omN4p+o4oaVMywiQUJDIuKfqQoKK8udy5gg4p+o4oaVMiwiYWIi4p+p4omN4p+o4oaVMywiQUJDIuKfqQ==">↗️</a><pre> <span class='Function'>+</span><span class='Modifier'>´˘</span> <span class='Bracket'>⟨</span><span class='Function'>↕</span><span class='Number'>2</span><span class='Separator'>,</span><span class='String'>&quot;ab&quot;</span><span class='Bracket'>⟩</span><span class='Function'>≍</span><span class='Bracket'>⟨</span><span class='Function'>↕</span><span class='Number'>3</span><span class='Separator'>,</span><span class='String'>&quot;ABC&quot;</span><span class='Bracket'>⟩</span>
+<p>In this case each call to <code><span class='Function'>+</span><span class='Modifier'>˝</span></code> returns a cell of the result. The result is a list, so its cells are units! Here, <a href="rank.html">Cells</a> (<code><span class='Modifier'>˘</span></code>) &quot;hides&quot; one axis from its operand, and the operand <code><span class='Function'>+</span><span class='Modifier'>˝</span></code> reduces out an axis, leaving zero axes—until Cells assembles the results, putting its axis back. Here, <code><span class='Function'>+</span><span class='Modifier'>´</span></code> would also be tolerated. But it's wrong, because each result really should be a zero-axis array. We can reveal this by making an array whose elements aren't atoms.</p>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=K8K0y5ggW+KfqOKGlTIsImFiIuKfqSzin6jihpUzLCJBQkMi4p+pXQoKK8udy5ggW+KfqOKGlTIsImFiIuKfqSzin6jihpUzLCJBQkMi4p+pXQ==">↗️</a><pre> <span class='Function'>+</span><span class='Modifier'>´˘</span> <span class='Bracket'>[⟨</span><span class='Function'>↕</span><span class='Number'>2</span><span class='Separator'>,</span><span class='String'>&quot;ab&quot;</span><span class='Bracket'>⟩</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='Function'>↕</span><span class='Number'>3</span><span class='Separator'>,</span><span class='String'>&quot;ABC&quot;</span><span class='Bracket'>⟩]</span>
<span class='Error'>Error: >: Elements didn't have equal shapes (contained shapes ⟨2⟩ and ⟨3⟩)</span>
- <span class='Function'>+</span><span class='Modifier'>˝˘</span> <span class='Bracket'>⟨</span><span class='Function'>↕</span><span class='Number'>2</span><span class='Separator'>,</span><span class='String'>&quot;ab&quot;</span><span class='Bracket'>⟩</span><span class='Function'>≍</span><span class='Bracket'>⟨</span><span class='Function'>↕</span><span class='Number'>3</span><span class='Separator'>,</span><span class='String'>&quot;ABC&quot;</span><span class='Bracket'>⟩</span>
+ <span class='Function'>+</span><span class='Modifier'>˝˘</span> <span class='Bracket'>[⟨</span><span class='Function'>↕</span><span class='Number'>2</span><span class='Separator'>,</span><span class='String'>&quot;ab&quot;</span><span class='Bracket'>⟩</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='Function'>↕</span><span class='Number'>3</span><span class='Separator'>,</span><span class='String'>&quot;ABC&quot;</span><span class='Bracket'>⟩]</span>
⟨ "ac" "ACE" ⟩
</pre>
<p>The function <code><span class='Function'>+</span><span class='Modifier'>´˘</span></code> tries to mix together the result elements into one big array, causing an error because they have different lengths, but <code><span class='Function'>+</span><span class='Modifier'>˝˘</span></code> keeps them as elements.</p>
@@ -61,14 +61,14 @@
⟨ "anti" "green" "up" ⟩ ⟨ "anti" "green" "down" ⟩
</pre>
-<p>One use is in the function <code><span class='Function'>&lt;</span><span class='Modifier2'>⊸</span><span class='Function'>∾</span></code>, which encloses the left argument before (<code><span class='Modifier2'>⊸</span></code>) <a href="join.html">joining</a> (<code><span class='Function'>∾</span></code>) it to the right argument. This is different from Join on its own because it treats the left argument as a single element.</p>
+<p>One use is in the function <code><span class='Function'>&lt;</span><span class='Modifier2'>⊸</span><span class='Function'>∾</span></code>, which encloses the left argument <a href="hook.html">before</a> (<code><span class='Modifier2'>⊸</span></code>) <a href="join.html">joining</a> (<code><span class='Function'>∾</span></code>) it to the right argument. This is different from Join on its own because it treats the left argument as a single element.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=InN0YXJ0IiDiiL4gIm1pZGRsZSLigL8iZW5kIgoKInN0YXJ0IiA84oq44oi+ICJtaWRkbGUi4oC/ImVuZCI=">↗️</a><pre> <span class='String'>&quot;start&quot;</span> <span class='Function'>∾</span> <span class='String'>&quot;middle&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;end&quot;</span>
⟨ 's' 't' 'a' 'r' 't' "middle" "end" ⟩
<span class='String'>&quot;start&quot;</span> <span class='Function'>&lt;</span><span class='Modifier2'>⊸</span><span class='Function'>∾</span> <span class='String'>&quot;middle&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;end&quot;</span>
⟨ "start" "middle" "end" ⟩
</pre>
-<p>For this purpose <code><span class='Brace'>{</span><span class='Bracket'>⟨</span><span class='Value'>𝕩</span><span class='Bracket'>⟩</span><span class='Brace'>}</span><span class='Modifier2'>⊸</span><span class='Function'>∾</span></code>, which turns the left argument into a 1-element list, also works. But maybe it doesn't really capture the intended meaning: it makes <code><span class='Value'>𝕨</span></code> into a whole new list to be added when all that's needed is to add one cell. This cell will be placed along the first axis, but it doesn't have an axis of its own. A similar example, showing how units are used as part of a computation, is to join each row of a matrix to the corresponding item of a list.</p>
+<p>For this purpose <code><span class='Function'>⋈</span><span class='Modifier2'>⊸</span><span class='Function'>∾</span></code>, which <a href="pair.html">enlists</a> the left argument giving the list <code><span class='Bracket'>⟨</span><span class='Value'>𝕨</span><span class='Bracket'>⟩</span></code>, also works. But maybe it doesn't really capture the intended meaning: it makes <code><span class='Value'>𝕨</span></code> into a whole new list to be added when all that's needed is to add one cell. This cell will be placed along the first axis, but it doesn't have an axis of its own. A similar example, showing how units are used as part of a computation, is to join each row of a matrix to the corresponding item of a list.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KD3ijJzLnOKGlTQpIOKIvsuYIOKGlTQ=">↗️</a><pre> <span class='Paren'>(</span><span class='Function'>=</span><span class='Modifier'>⌜˜</span><span class='Function'>↕</span><span class='Number'>4</span><span class='Paren'>)</span> <span class='Function'>∾</span><span class='Modifier'>˘</span> <span class='Function'>↕</span><span class='Number'>4</span>
┌─
╵ 1 0 0 0 0
@@ -90,7 +90,7 @@
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=POKKuOKIvuKMnMK0IOKfqCJ1cCLigL8iZG93biLin6k=">↗️</a><pre> <span class='Function'>&lt;</span><span class='Modifier2'>⊸</span><span class='Function'>∾</span><span class='Modifier'>⌜´</span> <span class='Bracket'>⟨</span><span class='String'>&quot;up&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;down&quot;</span><span class='Bracket'>⟩</span>
⟨ "up" "down" ⟩
</pre>
-<p>But this is only an array of strings, and not an array of lists of strings: the right result is <code><span class='Bracket'>⟨⟨</span><span class='String'>&quot;up&quot;</span><span class='Bracket'>⟩</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='String'>&quot;down&quot;</span><span class='Bracket'>⟩⟩</span></code>. And that's not the extend of our troubles: without an initial value we'll get the wrong result on longer arguments too, because the elements of the rightmost array get joined to the result lists as lists, not as elements.</p>
+<p>But this is only an array of strings, and not an array of lists of strings: the right result is <code><span class='Bracket'>⟨⟨</span><span class='String'>&quot;up&quot;</span><span class='Bracket'>⟩</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='String'>&quot;down&quot;</span><span class='Bracket'>⟩⟩</span></code>. And that's not the extent of our troubles: without an initial value we'll get the wrong result on longer arguments too, because the elements of the rightmost array get joined to the result lists as lists, not as elements.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=POKKuOKIvuKMnMK0IOKfqCJyZWQi4oC/ImJsdWUi4oC/ImdyZWVuIiwgInVwIuKAvyJkb3duIuKfqQ==">↗️</a><pre> <span class='Function'>&lt;</span><span class='Modifier2'>⊸</span><span class='Function'>∾</span><span class='Modifier'>⌜´</span> <span class='Bracket'>⟨</span><span class='String'>&quot;red&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;blue&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;green&quot;</span><span class='Separator'>,</span> <span class='String'>&quot;up&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;down&quot;</span><span class='Bracket'>⟩</span>
┌─
╵ ⟨ "red" 'u' 'p' ⟩ ⟨ "red" 'd' 'o' 'w' 'n' ⟩
@@ -99,7 +99,7 @@
</pre>
<p>To make things right, we need an array of lists for an initial value. Since it shouldn't add anything to the result, any lists it contains need to be empty. But what should its shape be? The result shape from Table is always the argument shapes joined together (<code><span class='Value'>𝕨</span><span class='Function'>∾</span><span class='Modifier2'>○</span><span class='Function'>≢</span><span class='Value'>𝕩</span></code>). The initial value shouldn't contribute the result shape, so it needs to have empty shape, or rank 0! We use Enclose to create the array <code><span class='Function'>&lt;</span><span class='Bracket'>⟨⟩</span></code> with no axes, because the result <em>will</em> have axes but the initial element needs to start without any. All the axes come from the list of choices.</p>
-<p>It goes deeper! The following (pretty tough) example uses arrays with various ranks in the argument, and they're handled quite well. The last one isn't really a choice, so it has no axes. If it were a one-element list then the result would have a meaningless length-1 axis. But not enclosing it would cause each character to be treated as an option, with unpleasant results.</p>
+<p>It goes deeper! The following (pretty tough) example uses arrays with various ranks in the argument, and they're handled just fine. The last one isn't really a choice, so it has no axes. If it were a one-element list then the result would have a meaningless length-1 axis. But not enclosing it would cause each character to be treated as an option, with unpleasant results.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=Zmxhdm9yIOKGkCDijYkg4oiY4oC/MiDipYogInVwIuKAvyJkb3duIuKAvyJjaGFybSLigL8ic3RyYW5nZSLigL8idG9wIuKAvyJib3R0b20iCig84p+o4p+pKSA84oq44oi+4oycwrQg4p+oInJlZCLigL8iYmx1ZSLigL8iZ3JlZW4iLCBmbGF2b3IsIDwicXVhcmsi4p+p">↗️</a><pre> <span class='Value'>flavor</span> <span class='Gets'>←</span> <span class='Function'>⍉</span> <span class='Modifier2'>∘</span><span class='Ligature'>‿</span><span class='Number'>2</span> <span class='Function'>⥊</span> <span class='String'>&quot;up&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;down&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;charm&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;strange&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;top&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;bottom&quot;</span>
<span class='Paren'>(</span><span class='Function'>&lt;</span><span class='Bracket'>⟨⟩</span><span class='Paren'>)</span> <span class='Function'>&lt;</span><span class='Modifier2'>⊸</span><span class='Function'>∾</span><span class='Modifier'>⌜´</span> <span class='Bracket'>⟨</span><span class='String'>&quot;red&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;blue&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;green&quot;</span><span class='Separator'>,</span> <span class='Value'>flavor</span><span class='Separator'>,</span> <span class='Function'>&lt;</span><span class='String'>&quot;quark&quot;</span><span class='Bracket'>⟩</span>
┌─
@@ -114,7 +114,7 @@
</pre>
<h3 id="broadcasting"><a class="header" href="#broadcasting">Broadcasting</a></h3>
-<p>Table isn't the only mapping function that gets along well with units. Here's an example with Each (<code><span class='Modifier'>¨</span></code>).</p>
+<p>Table isn't the only mapping function that gets along well with units. Here's an example with <a href="map.html#each">Each</a> (<code><span class='Modifier'>¨</span></code>).</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=PeKAv+KJoOKAv+KJoeKAv+KJoiB78J2VjvCdlal9wqggPCAz4oC/MuKliiJhYmNkZWYi">↗️</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='Brace'>{</span><span class='Function'>𝕎</span><span class='Value'>𝕩</span><span class='Brace'>}</span><span class='Modifier'>¨</span> <span class='Function'>&lt;</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Function'>⥊</span><span class='String'>&quot;abcdef&quot;</span>
⟨ 2 3 1 ⟨ 3 2 ⟩ ⟩
</pre>