diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-08-07 20:57:51 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-08-07 20:57:51 -0400 |
| commit | c7ef3aabb54791b597d4095011ff048c2a13f6ac (patch) | |
| tree | 45967d042b204df64097a57cf6c72c4b4be8d1f6 /docs/doc/fill.html | |
| parent | 7bf2aa4054b8378a76dff63acdccbcdad91f68e6 (diff) | |
Document use of fill elements for merge of empty
Diffstat (limited to 'docs/doc/fill.html')
| -rw-r--r-- | docs/doc/fill.html | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/docs/doc/fill.html b/docs/doc/fill.html index 843e80e8..e77872c4 100644 --- a/docs/doc/fill.html +++ b/docs/doc/fill.html @@ -6,7 +6,7 @@ <div class="nav"><a href="https://github.com/mlochbaum/BQN">BQN</a> / <a href="../index.html">main</a> / <a href="index.html">doc</a></div> <h1 id="fill-elements">Fill elements</h1> <p>A few array operations need an array element to use when no existing element applies. BQN tries to maintain a "default" element for every array, known as a fill element, for this purpose. If it's known, the fill element is a nested array structure where each atom is either <code><span class='Number'>0</span></code> or <code><span class='String'>' '</span></code>. If no fill is known, a function that requests it results in an error.</p> -<p>Fills are used by <a href="take.html">Take</a> (<code><span class='Function'>โ</span></code>) when a value in <code><span class='Value'>๐จ</span></code> is larger than the corresponding length in <code><span class='Value'>๐ฉ</span></code>, by the two <a href="shift.html">Nudge</a> functions (<code><span class='Function'>ยปยซ</span></code>) when <code><span class='Value'>๐ฉ</span></code> is non-empty, and by <a href="reshape.html">Reshape</a> (<code><span class='Function'>โฅ</span></code>) when <code><span class='Value'>๐จ</span></code> contains <code><span class='Function'>โ</span></code>. Except for these specific cases, the fill value an array has can't affect the program. The result of <a href="match.html">Match</a> (<code><span class='Function'>โก</span></code>) doesn't depend on fills, and any attempt to compute a fill can't cause side effects.</p> +<p>Fills are used by <a href="take.html">Take</a> (<code><span class='Function'>โ</span></code>) when a value in <code><span class='Value'>๐จ</span></code> is larger than the corresponding length in <code><span class='Value'>๐ฉ</span></code>, by the two <a href="shift.html">Nudge</a> functions (<code><span class='Function'>ยปยซ</span></code>) when <code><span class='Value'>๐ฉ</span></code> is non-empty, by <a href="couple.html">Merge</a> (<code><span class='Function'>></span></code>) when <code><span class='Value'>๐ฉ</span></code> is empty, and by <a href="reshape.html">Reshape</a> (<code><span class='Function'>โฅ</span></code>) when <code><span class='Value'>๐จ</span></code> contains <code><span class='Function'>โ</span></code>. Except for these specific cases, the fill value an array has can't affect the program. The result of <a href="match.html">Match</a> (<code><span class='Function'>โก</span></code>) doesn't depend on fills, and any attempt to compute a fill can't cause side effects.</p> <h2 id="using-fills">Using fills</h2> <p>For the examples in this section we'll use the fact that an all-number array usually has <code><span class='Number'>0</span></code> as a fill while a string has <code><span class='String'>' '</span></code> (BQN maintains fills alongside array values rather than deriving them from arrays, so it's possible to construct arrays where this isn't true, but this probably wouldn't happen in ordinary code).</p> <p><a href="take.html">Take</a> (<code><span class='Function'>โ</span></code>) and <a href="shift.html">Nudge</a> (<code><span class='Function'>ยปยซ</span></code>) in either direction use the fill for padding, to extend the array past its boundary. For example, <code><span class='Value'>๐จ</span><span class='Function'>โ</span><span class='Value'>๐ฉ</span></code> will add elements to one side when a number in <code><span class='Function'>|</span><span class='Value'>๐จ</span></code> is larger than the corresponding length in <code><span class='Function'>โข</span><span class='Value'>๐ฉ</span></code>.</p> @@ -26,6 +26,7 @@ <span class='Function'>ยป</span><span class='Bracket'>โจโฉ</span> <span class='Comment'># Fill not needed </span>โจโฉ </pre> +<p>If the argument to <a href="couple.html">Merge</a> is empty then its result will be as well, since the shape <code><span class='Function'>โข</span><span class='Value'>๐ฉ</span></code> is a prefix of <code><span class='Function'>โข></span><span class='Value'>๐ฉ</span></code>. However, the remainder of the result shape is determined by the elements of <code><span class='Value'>๐ฉ</span></code>, so if there are none then Merge uses the fill element to decide what the result shape should be.</p> <p><a href="reshape.html#computed-lengths">Reshape</a> (<code><span class='Function'>โฅ</span></code>) uses the fill when <code><span class='Value'>๐จ</span></code> contains <code><span class='Function'>โ</span></code> and the product of the rest of <code><span class='Value'>๐จ</span></code> doesn't evenly divide the number of elements in <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=4oaR4oC/OCDipYogImNvbXBsZXRlcGFydCI=">โ๏ธ</a><pre> <span class='Function'>โ</span><span class='Ligature'>โฟ</span><span class='Number'>8</span> <span class='Function'>โฅ</span> <span class='String'>"completepart"</span> โโ |
