diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-07-24 22:47:46 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-07-24 22:47:46 -0400 |
| commit | a17782ce2ec31709ce30edb3d96fe2f3a9a6ed1f (patch) | |
| tree | b601681b2282f1a51042f8faf5bfe0e0242c0c31 /docs | |
| parent | 436bf368830c828f8008bf55632e2bb4c2a2578f (diff) | |
Documentation on fill elements
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/doc/arrayrepr.html | 4 | ||||
| -rw-r--r-- | docs/doc/embed.html | 2 | ||||
| -rw-r--r-- | docs/doc/fill.html | 89 | ||||
| -rw-r--r-- | docs/doc/glossary.html | 2 | ||||
| -rw-r--r-- | docs/doc/index.html | 1 | ||||
| -rw-r--r-- | docs/doc/match.html | 2 | ||||
| -rw-r--r-- | docs/doc/order.html | 2 | ||||
| -rw-r--r-- | docs/doc/pick.html | 4 | ||||
| -rw-r--r-- | docs/doc/reshape.html | 4 | ||||
| -rw-r--r-- | docs/doc/shift.html | 2 | ||||
| -rw-r--r-- | docs/doc/take.html | 4 | ||||
| -rw-r--r-- | docs/doc/types.html | 2 |
12 files changed, 104 insertions, 14 deletions
diff --git a/docs/doc/arrayrepr.html b/docs/doc/arrayrepr.html index fa2332c6..4c7f8268 100644 --- a/docs/doc/arrayrepr.html +++ b/docs/doc/arrayrepr.html @@ -30,7 +30,7 @@ ┘ </pre> <p>There are several different ways to show arrays: as a string <code><span class='String'>""</span></code>, with brackets <code><span class='Bracket'>⟨⟩</span></code>, or with corners <code><span class='Value'>┌</span></code> and <code><span class='Value'>┘</span></code>. We'll start with the most general, the corners. These show arrays of any rank while the other two ways are special cases for lists.</p> -<p>Array displays show only the array shape and elements. The fill is an inferred property and the display never indicates or depends on it.</p> +<p>Array displays show only the array shape and elements. The <a href="fill.html">fill</a> is an inferred property and the display never indicates or depends on it.</p> <h3 id="corners">Corners</h3> <p>Those top-left and bottom-right corners are a distinctive part of BQN's display, as other systems almost always completely enclose the contents. BQN could add the other two corners, naturally; it just doesn't. Within the corners, elements are separated by whitespace only, and generally aligned to the top left.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4p+oMiwieHki4p+p4omN4p+oMuKAvzLipYoiYWJjZCIsNOKfqSAgIyBOZXN0ZWQgMsOXMiBhcnJheQ==">↗️</a><pre> <span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='String'>"xy"</span><span class='Bracket'>⟩</span><span class='Function'>≍</span><span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Function'>⥊</span><span class='String'>"abcd"</span><span class='Separator'>,</span><span class='Number'>4</span><span class='Bracket'>⟩</span> <span class='Comment'># Nested 2×2 array @@ -160,7 +160,7 @@ <p>This case also covers empty lists, which are shown as <code><span class='Bracket'>⟨⟩</span></code>. This includes an empty string, as the only difference between an empty string and any other empty list is its fill element and array displays don't depend on the fill.</p> <h2 id="list-literals">List literals</h2> <p><em>The tutorial section <a href="../tutorial/list.html#list-notation">here</a> also covers this topic.</em></p> -<p>There are three kinds literal notation for lists: strings, list notation, and stranding. Strings indicate character lists (with space for the fill) and the other two can combine any sequence of elements.</p> +<p>There are three kinds literal notation for lists: strings, list notation, and stranding. Strings indicate character lists (with space for the <a href="fill.html">fill</a>) and the other two can combine any sequence of elements.</p> <h3 id="strings">Strings</h3> <p>A <strong>string</strong> consists of a sequence of characters surrounded by double quotes <code><span class='String'>""</span></code>. The only rule for the characters inside is that any double quote must be escaped by repeating it twice; otherwise the string ends at that point.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=Ii0nw5clIiIqIgoKIi0nw5clIioiICAjIEVzY2FwaW5nIGZhaWx1cmU=">↗️</a><pre> <span class='String'>"-'×%""*"</span> diff --git a/docs/doc/embed.html b/docs/doc/embed.html index 4b4e0365..31a5f22e 100644 --- a/docs/doc/embed.html +++ b/docs/doc/embed.html @@ -34,7 +34,7 @@ <p>You can also use an array to pass multiple functions or other values from JS into BQN all at once. However, a JS array can't be used directly in BQN because its shape isn't known. The function <code><span class='Value'>list</span><span class='Paren'>()</span></code> converts a JS array into a BQN list by using its length for the shape; the next section has a few more details.</p> <h2 id="js-encodings">JS encodings</h2> <p>In the programs above we've used numbers and functions of one argument, which mean the same thing in BQN and JS. This isn't the case for all types: although every BQN value is stored as some JS value, the way it's represented may not be obvious and there are many JS values that don't represent any BQN value and could cause errors. BQN operations don't verify that their inputs are valid BQN values (this would have a large performance cost), so it's up to the JS programmer to make sure that values passed in are valid. To do this, you need to know the encodings for each of the seven BQN <a href="types.html">types</a> you're going to use.</p> -<p>The two atomic data values are simple: numbers are just JS numbers, and characters are strings containing a single code point. Arrays <em>are</em> JS arrays, but with some extra information. Since JS arrays are 1-dimensional, a BQN array <code><span class='Value'>a</span></code> is stored as the element list <code><span class='Function'>⥊</span><span class='Value'>a</span></code>. Its shape <code><span class='Function'>≢</span><span class='Value'>a</span></code>, a list of numbers, is <code><span class='Value'>a.sh</span></code> in JS (the shape isn't necessarily a BQN array so it doesn't have to have a <code><span class='Value'>sh</span></code> property). Optionally, its fill element is <code><span class='Value'>a.fill</span></code>. Note that a BQN string is not a JS string, but instead an array of BQN characters, or JS strings. To convert it to a JS string you can use <code><span class='Value'>str.join</span><span class='Paren'>(</span><span class='String'>""</span><span class='Paren'>)</span></code>.</p> +<p>The two atomic data values are simple: numbers are just JS numbers, and characters are strings containing a single code point. Arrays <em>are</em> JS arrays, but with some extra information. Since JS arrays are 1-dimensional, a BQN array <code><span class='Value'>a</span></code> is stored as the element list <code><span class='Function'>⥊</span><span class='Value'>a</span></code>. Its shape <code><span class='Function'>≢</span><span class='Value'>a</span></code>, a list of numbers, is <code><span class='Value'>a.sh</span></code> in JS (the shape isn't necessarily a BQN array so it doesn't have to have a <code><span class='Value'>sh</span></code> property). Optionally, its <a href="fill.html">fill element</a> is <code><span class='Value'>a.fill</span></code>. Note that a BQN string is not a JS string, but instead an array of BQN characters, or JS strings. To convert it to a JS string you can use <code><span class='Value'>str.join</span><span class='Paren'>(</span><span class='String'>""</span><span class='Paren'>)</span></code>.</p> <p>There are two utilities for converting from JS to BQN data: <code><span class='Value'>list</span><span class='Paren'>(</span><span class='Value'>[…]</span><span class='Paren'>)</span></code> converts a JS array to a BQN list, and <code><span class='Value'>str</span><span class='Paren'>(</span><span class='String'>"JS string"</span><span class='Paren'>)</span></code> converts a string.</p> <p>Operations are all stored as JS functions, with one or two arguments for the inputs. The type is determined by the <code><span class='Value'>.m</span></code> property, which is <code><span class='Number'>1</span></code> for a 1-modifier and <code><span class='Number'>2</span></code> for a 2-modifier, and undefined or falsy for a function. Functions might be called with one or two arguments. In either case, <code><span class='Value'>𝕩</span></code> is the first argument; <code><span class='Value'>𝕨</span></code>, if present, is the second. Note that <code><span class='Function'>F</span><span class='Paren'>(</span><span class='Value'>x</span><span class='Separator'>,</span><span class='Value'>w</span><span class='Paren'>)</span></code> in JS corresponds to <code><span class='Value'>w</span> <span class='Function'>F</span> <span class='Value'>x</span></code> in BQN, reversing the visual ordering of the arguments! For modifiers there's no such reversal, as <code><span class='Value'>𝕗</span></code> is always the first argument, and for 2-modifiers <code><span class='Value'>𝕘</span></code> is the second argument. As in BQN, a modifier may or may not return a function.</p> <p>Operations may have some extra properties set that aren't terribly important for the JS programmer: for each primitive <code><span class='Value'>p</span></code>, <code><span class='Value'>p.glyph</span></code> gives its glyph, and for a compound operation <code><span class='Value'>o</span></code> such as a train, or a modifier with bound operands, <code><span class='Value'>o.repr</span><span class='Paren'>()</span></code> decomposes it into its parts. It wouldn't make sense to define either of these properties for a function created in JS.</p> diff --git a/docs/doc/fill.html b/docs/doc/fill.html new file mode 100644 index 00000000..5ef9baf1 --- /dev/null +++ b/docs/doc/fill.html @@ -0,0 +1,89 @@ +<head> + <link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/> + <link href="../style.css" rel="stylesheet"/> + <title>BQN: Fill elements</title> +</head> +<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="pick.html">First</a> (<code><span class='Function'>⊑</span></code>) and <a href="reshape.html">Reshape</a> (<code><span class='Function'>⥊</span></code>) when <code><span class='Value'>𝕩</span></code> is empty. 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> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=wq83IOKGkSA04qWKMyAgICAgIyBGaWxsIHdpdGggMAoKwq83IOKGkSAicXJzdCIgICMgRmlsbCB3aXRoIHNwYWNl">↗️</a><pre> <span class='Number'>¯7</span> <span class='Function'>↑</span> <span class='Number'>4</span><span class='Function'>⥊</span><span class='Number'>3</span> <span class='Comment'># Fill with 0 +</span>⟨ 0 0 0 3 3 3 3 ⟩ + + <span class='Number'>¯7</span> <span class='Function'>↑</span> <span class='String'>"qrst"</span> <span class='Comment'># Fill with space +</span>" qrst" +</pre> +<p>Nudge Left or Right shifts the array over and places a fill in the vacated space, effectively extending it backwards by one. If <code><span class='Value'>𝕩</span></code> is empty then it shouldn't give an error, but it's safer not to rely on this.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=wrvCqCDin6g04qWKMywicXJzdCLin6kKCjPihpHin6jin6kgICMgRmlsbCB1bmtub3duCgrCu+KfqOKfqSAgICMgRmlsbCBub3QgbmVlZGVk">↗️</a><pre> <span class='Function'>»</span><span class='Modifier'>¨</span> <span class='Bracket'>⟨</span><span class='Number'>4</span><span class='Function'>⥊</span><span class='Number'>3</span><span class='Separator'>,</span><span class='String'>"qrst"</span><span class='Bracket'>⟩</span> +⟨ ⟨ 0 3 3 3 ⟩ " qrs" ⟩ + + <span class='Number'>3</span><span class='Function'>↑</span><span class='Bracket'>⟨⟩</span> <span class='Comment'># Fill unknown +</span>ERROR + + <span class='Function'>»</span><span class='Bracket'>⟨⟩</span> <span class='Comment'># Fill not needed +</span>⟨⟩ +</pre> +<p><a href="pick.html">First</a> (<code><span class='Function'>⊑</span></code>) and <a href="reshape.html">Reshape</a> (<code><span class='Function'>⥊</span></code>) use the fill when <code><span class='Value'>𝕩</span></code> is empty, and in the case of Reshape only when the result needs to be non-empty.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqRICIiCgo0IOKlisKoIOKfqOKGlTAsICIi4p+pCgow4oC/MyDipYog4p+o4p+pICAjIEZpbGwgbm90IG5lZWRlZA==">↗️</a><pre> <span class='Function'>⊑</span> <span class='String'>""</span> +' ' + + <span class='Number'>4</span> <span class='Function'>⥊</span><span class='Modifier'>¨</span> <span class='Bracket'>⟨</span><span class='Function'>↕</span><span class='Number'>0</span><span class='Separator'>,</span> <span class='String'>""</span><span class='Bracket'>⟩</span> +⟨ ⟨ 0 0 0 0 ⟩ " " ⟩ + + <span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>3</span> <span class='Function'>⥊</span> <span class='Bracket'>⟨⟩</span> <span class='Comment'># Fill not needed +</span>↕0‿3 +</pre> +<p>If for some reason you need to find an array's fill element, the easiest way is <code><span class='Function'>⊑</span><span class='Number'>0</span><span class='Function'>⥊</span><span class='Value'>a</span></code>.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqRMOKliiJzdHJpbmci">↗️</a><pre> <span class='Function'>⊑</span><span class='Number'>0</span><span class='Function'>⥊</span><span class='String'>"string"</span> +' ' +</pre> +<h2 id="how-fills-are-computed">How fills are computed</h2> +<p>For the exact requirements placed on fill, see <a href="../spec/inferred.html#fill-elements">the specification</a> (particularly "required functions"). This section loosely describes behavior in existing BQN implementations, and includes some parts that aren't required in the specification.</p> +<p>A fill element should encompass something that's necessarily true for all elements of an array. If the way an array is computed implies it's all numbers, the fill should be <code><span class='Number'>0</span></code>. If every element is a list of two numbers, then the fill should be <code><span class='Bracket'>⟨</span><span class='Number'>0</span><span class='Separator'>,</span><span class='Number'>0</span><span class='Bracket'>⟩</span></code>. If every element is a list but the lengths might vary, <code><span class='Bracket'>⟨⟩</span></code> is probably a reasonable fill element.</p> +<p>For <a href="arithmetic.html">arithmetic</a> primitives, the fill is found by the rules of pervasion, applying the function to both argument fills. Generally this means it consists of <code><span class='Number'>0</span></code>, but character arithmetic also allows space fills.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=wrsgImFiYyIgKyA04oC/M+KAvzI=">↗️</a><pre> <span class='Function'>»</span> <span class='String'>"abc"</span> <span class='Function'>+</span> <span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span> +" ee" +</pre> +<p><a href="map.html">Mapping</a> modifiers Each and Table (<code><span class='Modifier'>¨⌜</span></code>) might try to follow a similar strategy, applying <code><span class='Function'>𝔽</span></code> to argument fills to obtain the result fill. The absolute rule here is that this computation cannot cause side effects or an error, so for a complicated <code><span class='Function'>𝔽</span></code> such as a block function this procedure is likely to be aborted to avoid disrupting the rest of the program.</p> +<p>Most other primitives fit in one of three broad categories as shown in the table below. Structural primitives, indicated by <code><span class='Function'>⊢</span></code>, don't change the fill of <code><span class='Value'>𝕩</span></code>. Combining structural primitives, indicated by <code><span class='Value'>∩</span></code>, only depend on the fill of all combined arrays—elements of <code><span class='Value'>𝕩</span></code> in the one-argument case, or <code><span class='Value'>𝕨</span></code> and <code><span class='Value'>𝕩</span></code> in the two-argument case. Finally, many functions such as <a href="search.html">search functions</a> return only numbers and have a fill of <code><span class='Number'>0</span></code>.</p> +<table> +<thead> +<tr> +<th>Fill</th> +<th>Monads</th> +<th>Dyads</th> +<th>Modifiers</th> +</tr> +</thead> +<tbody> +<tr> +<td><code><span class='Function'>⊢</span></code></td> +<td><code><span class='Function'>∧∨⥊≍»«⌽⍉⊏⍷</span></code></td> +<td><code><span class='Function'>⥊↑↓↕⌽⍉/⊏</span></code></td> +<td><code><span class='Function'>𝔽</span><span class='Modifier'>`</span></code></td> +</tr> +<tr> +<td><code><span class='Value'>∩</span></code></td> +<td><code><span class='Function'>>∾</span></code></td> +<td><code><span class='Function'>∾≍»«</span></code></td> +<td></td> +</tr> +<tr> +<td><code><span class='Number'>0</span></code></td> +<td><code><span class='Function'>≢/⍋⍒∊⊐⊒</span></code></td> +<td><code><span class='Function'>⍋⍒⊐⊒∊⍷</span></code></td> +<td></td> +</tr> +</tbody> +</table> +<p>Besides these, there are a few primitives with special fills. <a href="enclose.html">Enclose</a> (<code><span class='Function'><</span></code>) uses a fill derived directly from <code><span class='Value'>𝕩</span></code>, with all numbers replaced by <code><span class='Number'>0</span></code> and characters by <code><span class='String'>' '</span></code> (if it contains non-data atoms, the fill doesn't exist). <a href="range.html">Range</a> (<code><span class='Function'>↕</span></code>) does the same, although the reason is less obvious: the result elements don't match <code><span class='Value'>𝕩</span></code>, but they have the same structure.</p> +<p><a href="prefixes.html">Prefixes and Suffixes</a> (<code><span class='Function'>↑↓</span></code>) use <code><span class='Number'>0</span><span class='Function'>↑</span><span class='Value'>𝕩</span></code> for the fill, as do <a href="group.html">Group</a> and Group Indices (<code><span class='Function'>⊔</span></code>) in the single-axis case. Fills for multi-axis <code><span class='Function'>⊔</span></code> are more complicated, but follow the rule that variable-length axes are changed to length 0. The <em>elements</em> of the result of <code><span class='Function'>⊔</span></code> also have a fill specified: the same as <code><span class='Value'>𝕩</span></code> for Group, or <code><span class='Number'>0</span></code> for Group Indices.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=NiDihpEg4oaR4oaVMyAgIyBUd28gZmlsbHMgYXQgdGhlIGVuZAoKwrvCqCAz4oC/NOKAvzEgL+KKuOKKlCAiYWJjMDEyM0Ei">↗️</a><pre> <span class='Number'>6</span> <span class='Function'>↑</span> <span class='Function'>↑↕</span><span class='Number'>3</span> <span class='Comment'># Two fills at the end +</span>⟨ ⟨⟩ ⟨ 0 ⟩ ⟨ 0 1 ⟩ ⟨ 0 1 2 ⟩ ⟨⟩ ⟨⟩ ⟩ + + <span class='Function'>»</span><span class='Modifier'>¨</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>1</span> <span class='Function'>/</span><span class='Modifier2'>⊸</span><span class='Function'>⊔</span> <span class='String'>"abc0123A"</span> +⟨ " ab" " 012" " " ⟩ +</pre> diff --git a/docs/doc/glossary.html b/docs/doc/glossary.html index f1c8d39e..99e96d32 100644 --- a/docs/doc/glossary.html +++ b/docs/doc/glossary.html @@ -119,7 +119,7 @@ <li><strong>Nothing</strong>: A special value-like entity that comes from <code><span class='Nothing'>·</span></code>, <code><span class='Value'>𝕨</span></code> in a function with no left argument, or a function called on nothing.</li> <li><strong>Statement</strong>: An expression, or nothing (<code><span class='Nothing'>·</span></code>).</li> <li><strong>Ligature</strong>: The character <code><span class='Ligature'>‿</span></code>.</li> -<li><a href="syntax.html#list-notation"><strong>List notation</strong></a>: The angle brackets <code><span class='Bracket'>⟨⟩</span></code> or ligatures used to indicate a list.</li> +<li><a href="arrayrepr.html#brackets"><strong>List notation</strong></a>: The angle brackets <code><span class='Bracket'>⟨⟩</span></code> or ligatures used to indicate a list.</li> </ul> <h2 id="assignment-and-scoping">Assignment and scoping</h2> <ul> diff --git a/docs/doc/index.html b/docs/doc/index.html index ff2c4ade..e7ab568f 100644 --- a/docs/doc/index.html +++ b/docs/doc/index.html @@ -25,6 +25,7 @@ <li><a href="based.html">Based array theory</a></li> <li><a href="arrayrepr.html">Array notation and display</a></li> <li><a href="indices.html">Array indices</a></li> +<li><a href="fill.html">Fill elements</a></li> <li><a href="leading.html">The leading axis model</a></li> <li><a href="train.html">Function trains</a></li> <li><a href="block.html">Blocks</a> (including function and modifier definition)</li> diff --git a/docs/doc/match.html b/docs/doc/match.html index dbf0b301..3fd112f0 100644 --- a/docs/doc/match.html +++ b/docs/doc/match.html @@ -22,7 +22,7 @@ <span class='String'>"abc"</span> <span class='Function'>≡</span> <span class='String'>"ab"</span> 0 </pre> -<p>Match compares arrays based on their fundamental properties—<a href="shape.html">shape</a> and elements—and not the <a href="../spec/inferred.html#fill-elements">fill element</a>, which is an inferred property. Since it can be computed differently in different implementations, using the fill element in Match could lead to some confusing results. Even if the implementation doesn't define a fill for <code><span class='String'>'a'</span><span class='Ligature'>‿</span><span class='String'>'b'</span><span class='Ligature'>‿</span><span class='String'>'c'</span></code>, it should still be considered to match <code><span class='String'>"abc"</span></code>.</p> +<p>Match compares arrays based on their fundamental properties—<a href="shape.html">shape</a> and elements—and not the <a href="fill.html">fill element</a>, which is an inferred property. Since it can be computed differently in different implementations, using the fill element in Match could lead to some confusing results. Even if the implementation doesn't define a fill for <code><span class='String'>'a'</span><span class='Ligature'>‿</span><span class='String'>'b'</span><span class='Ligature'>‿</span><span class='String'>'c'</span></code>, it should still be considered to match <code><span class='String'>"abc"</span></code>.</p> <p>To give a precise definition, two arrays are considered to match if they have the same shape and all corresponding elements from the two arrays match. Every array has a finite <a href="depth.html">depth</a> so this recursive definition always ends up comparing non-arrays, or atoms. An array never matches an atom, so the result if only one argument is an atom is <code><span class='Number'>0</span></code>. The interesting case is when both arguments are atoms, discussed below.</p> <h2 id="atomic-equality">Atomic equality</h2> <p>Atoms in BQN have six possible <a href="types.html">types</a>: number, character, function, 1-modifier, 2-modifier, and namespace. Equality is not allowed to fail for any two arguments, so it needs to be defined on all of these types.</p> diff --git a/docs/doc/order.html b/docs/doc/order.html index 24db519a..3b281ee3 100644 --- a/docs/doc/order.html +++ b/docs/doc/order.html @@ -21,7 +21,7 @@ <span class='Function'>∨</span> <span class='String'>"δαβγ"</span> "δγβα" </pre> -<p>Sort Down always <a href="match.html">matches</a> Sort Up <a href="reverse.html">reversed</a>, <code><span class='Function'>⌽</span><span class='Modifier2'>∘</span><span class='Function'>∧</span></code>. The reason for this is that BQN's array ordering is a <a href="https://en.wikipedia.org/wiki/Total_order">total order</a>, meaning that if one array doesn't come earlier or later that another array in the ordering then the two arrays match. Since any two non-matching argument cells are strictly ordered, they will have one ordering in <code><span class='Function'>∧</span></code> and the opposite ordering in <code><span class='Function'>∨</span></code>. With the reverse, any pair of non-matching cells are ordered the same way in <code><span class='Function'>⌽</span><span class='Modifier2'>∘</span><span class='Function'>∧</span></code> and <code><span class='Function'>∨</span></code>. Since these two results have the same major cells in the same order, they match. However, note that the results will not always behave identically because Match doesn't take fill elements into account (if you're curious, take a look at <code><span class='Function'>⊑</span><span class='Modifier'>¨</span><span class='Function'>∨</span><span class='Bracket'>⟨</span><span class='Function'>↕</span><span class='Number'>0</span><span class='Separator'>,</span><span class='String'>""</span><span class='Bracket'>⟩</span></code> versus <code><span class='Function'>⊑</span><span class='Modifier'>¨</span><span class='Function'>⌽</span><span class='Modifier2'>∘</span><span class='Function'>∧</span><span class='Bracket'>⟨</span><span class='Function'>↕</span><span class='Number'>0</span><span class='Separator'>,</span><span class='String'>""</span><span class='Bracket'>⟩</span></code>).</p> +<p>Sort Down always <a href="match.html">matches</a> Sort Up <a href="reverse.html">reversed</a>, <code><span class='Function'>⌽</span><span class='Modifier2'>∘</span><span class='Function'>∧</span></code>. The reason for this is that BQN's array ordering is a <a href="https://en.wikipedia.org/wiki/Total_order">total order</a>, meaning that if one array doesn't come earlier or later that another array in the ordering then the two arrays match. Since any two non-matching argument cells are strictly ordered, they will have one ordering in <code><span class='Function'>∧</span></code> and the opposite ordering in <code><span class='Function'>∨</span></code>. With the reverse, any pair of non-matching cells are ordered the same way in <code><span class='Function'>⌽</span><span class='Modifier2'>∘</span><span class='Function'>∧</span></code> and <code><span class='Function'>∨</span></code>. Since these two results have the same major cells in the same order, they match. However, note that the results will not always behave identically because Match doesn't take <a href="fill.html">fill elements</a> into account (if you're curious, take a look at <code><span class='Function'>⊑</span><span class='Modifier'>¨</span><span class='Function'>∨</span><span class='Bracket'>⟨</span><span class='Function'>↕</span><span class='Number'>0</span><span class='Separator'>,</span><span class='String'>""</span><span class='Bracket'>⟩</span></code> versus <code><span class='Function'>⊑</span><span class='Modifier'>¨</span><span class='Function'>⌽</span><span class='Modifier2'>∘</span><span class='Function'>∧</span><span class='Bracket'>⟨</span><span class='Function'>↕</span><span class='Number'>0</span><span class='Separator'>,</span><span class='String'>""</span><span class='Bracket'>⟩</span></code>).</p> <h2 id="grade">Grade</h2> <p><em>See the <a href="https://aplwiki.com/wiki/Grade">APL Wiki page</a> for a few more examples. BQN only has the monadic form.</em></p> <p>Grade is more abstract than Sort. Rather than rearranging the argument's cells immediately, it returns a list of indices (more precisely, a permutation) giving the ordering that would sort them.</p> diff --git a/docs/doc/pick.html b/docs/doc/pick.html index 0926b3a0..b0e99195 100644 --- a/docs/doc/pick.html +++ b/docs/doc/pick.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="pick">Pick</h1> <p>Pick (<code><span class='Function'>⊑</span></code>) chooses elements from <code><span class='Value'>𝕩</span></code> based on <a href="indices.html">index</a> lists from <code><span class='Value'>𝕨</span></code>. <code><span class='Value'>𝕨</span></code> can be a plain list, or even one number if <code><span class='Value'>𝕩</span></code> is a list, in order to get one element from <code><span class='Value'>𝕩</span></code>. It can also be an array of index lists, or have deeper array structure: each index list will be replaced with the element of <code><span class='Value'>𝕩</span></code> at that index, effectively applying to <code><span class='Value'>𝕨</span></code> at <a href="depth.html#the-depth-modifier">depth</a> 1.</p> -<p>With no <code><span class='Value'>𝕨</span></code>, monadic <code><span class='Function'>⊑</span><span class='Value'>𝕩</span></code> takes the first element of <code><span class='Value'>𝕩</span></code> in index order, or its fill element if <code><span class='Value'>𝕩</span></code> is empty (causing an error if no fill is known).</p> +<p>With no <code><span class='Value'>𝕨</span></code>, monadic <code><span class='Function'>⊑</span><span class='Value'>𝕩</span></code> takes the first element of <code><span class='Value'>𝕩</span></code> in index order, or its <a href="fill.html">fill element</a> if <code><span class='Value'>𝕩</span></code> is empty (causing an error if no fill is known).</p> <p>While sometimes "scatter-point" indexing is necessary, using Pick to select multiple elements from <code><span class='Value'>𝕩</span></code> is less array-oriented than <a href="select.html">Select</a> (<code><span class='Function'>⊏</span></code>), and probably slower. Consider rearranging your data so that you can select along axes instead of picking out elements.</p> <h2 id="one-element">One element</h2> <p>When the left argument is a number, Pick gets an element from a list:</p> @@ -55,7 +55,7 @@ <span class='Function'>⊑</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'>5</span><span class='Ligature'>‿</span><span class='Number'>1</span> ⟨ 0 0 0 0 ⟩ </pre> -<p>If <code><span class='Value'>𝕩</span></code> is empty then Pick always results in an error. First never gives an error: instead it returns the fill element for <code><span class='Value'>𝕩</span></code>.</p> +<p>If <code><span class='Value'>𝕩</span></code> is empty then Pick always results in an error. First never gives an error: instead it returns the <a href="fill.html">fill element</a> for <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=4oqRICIiCuKKkSDiiaLPgAriipEgMOKGkTzin6giICAiLOKGlTTin6k=">↗️</a><pre> <span class='Function'>⊑</span> <span class='String'>""</span> ' ' <span class='Function'>⊑</span> <span class='Function'>≢</span><span class='Number'>π</span> diff --git a/docs/doc/reshape.html b/docs/doc/reshape.html index 73c85f83..5736da15 100644 --- a/docs/doc/reshape.html +++ b/docs/doc/reshape.html @@ -142,7 +142,7 @@ 235 236 237 ┘ </pre> -<p>If the left argument implies a larger number of elements, then the argument elements are reused cyclically. Below, we reach the last element <code><span class='Number'>247</span></code> and start over at <code><span class='Number'>135</span></code>. If the array doesn't have any elements to start with, its fill value is used instead, but it's probably best not to invoke this case!</p> +<p>If the left argument implies a larger number of elements, then the argument elements are reused cyclically. Below, we reach the last element <code><span class='Number'>247</span></code> and start over at <code><span class='Number'>135</span></code>. If the array doesn't have any elements to start with, its <a href="fill.html">fill element</a> is used instead, but it's probably best not to invoke this case!</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MTUg4qWKIGEKCjQg4qWKIOKGlTAgICMgRmlsbCBmb3Ig4oaVMCBpcyAw">↗️</a><pre> <span class='Number'>15</span> <span class='Function'>⥊</span> <span class='Value'>a</span> ⟨ 135 136 137 145 146 147 235 236 237 245 246 247 135 136 137 ⟩ @@ -176,7 +176,7 @@ <li><code><span class='Modifier2'>∘</span></code> says the length must be an exact fit, and gives an error in such a case.</li> <li><code><span class='Function'>⌊</span></code> rounds the length down, so that some elements are discarded.</li> <li><code><span class='Function'>⌽</span></code> rounds the length up, repeating elements to make up the difference.</li> -<li><code><span class='Function'>↑</span></code> rounds the length up, but uses the argument's fill values for the needed extra elements.</li> +<li><code><span class='Function'>↑</span></code> rounds the length up, but uses the argument's fill for the needed extra elements.</li> </ul> <p>These values are just BQN primitives of course. They're not called by Reshape or anything like that; the primitives are just chosen to suggest the corresponding functionality.</p> <p>Here's an example. If we try to turn five elements into two rows, <code><span class='Modifier2'>∘</span></code> gives an error, <code><span class='Function'>⌊</span></code> drops the last element, <code><span class='Function'>⌽</span></code> uses the first element again, and <code><span class='Function'>↑</span></code> uses a fill element (like <code><span class='Number'>5</span><span class='Function'>↑</span><span class='String'>"abcde"</span></code> would).</p> diff --git a/docs/doc/shift.html b/docs/doc/shift.html index c4b142c6..a85fce92 100644 --- a/docs/doc/shift.html +++ b/docs/doc/shift.html @@ -12,7 +12,7 @@ <span class='String'>"end"</span> <span class='Function'>«</span> <span class='String'>"add to the "</span> <span class='Comment'># Shift After </span>" to the end" </pre> -<p>The cells to add come from <code><span class='Value'>𝕨</span></code> if it's present, as shown above. Otherwise, a single cell of fill values for <code><span class='Value'>𝕩</span></code> is used. This kind of shift, which moves cells in <code><span class='Value'>𝕩</span></code> over by just one, is called a "nudge".</p> +<p>The cells to add come from <code><span class='Value'>𝕨</span></code> if it's present, as shown above. Otherwise, a single cell of <a href="fill.html">fill elements</a> for <code><span class='Value'>𝕩</span></code> is used. This kind of shift, which moves cells in <code><span class='Value'>𝕩</span></code> over by just one, is called a "nudge".</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=wrsgImFiY2QiICAgIyBOdWRnZQrCqyAx4oC/MuKAvzMgICAgIyBOdWRnZSBCYWNr">↗️</a><pre> <span class='Function'>»</span> <span class='String'>"abcd"</span> <span class='Comment'># Nudge </span>" abc" <span class='Function'>«</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='Comment'># Nudge Back diff --git a/docs/doc/take.html b/docs/doc/take.html index bf54a147..2126479d 100644 --- a/docs/doc/take.html +++ b/docs/doc/take.html @@ -37,7 +37,7 @@ <ul> <li><code><span class='Value'>𝕩</span></code> can be an atom, or array of any rank (the result will be an array).</li> <li><code><span class='Value'>𝕨</span></code> can be negative to take or drop from the end instead of the beginning.</li> -<li>For Take, if <code><span class='Value'>𝕨</span></code> is larger than the length of <code><span class='Value'>𝕩</span></code>, then fills are added.</li> +<li>For Take, if <code><span class='Value'>𝕨</span></code> is larger than the length of <code><span class='Value'>𝕩</span></code>, then <a href="fill.html">fills</a> are added.</li> <li><code><span class='Value'>𝕨</span></code> can have multiple numbers corresponding to leading axes of <code><span class='Value'>𝕩</span></code>.</li> <li><code><span class='Value'>𝕨</span></code> is allowed to be longer than the rank of <code><span class='Value'>𝕩</span></code>; <code><span class='Value'>𝕩</span></code> will be extended to fit.</li> </ul> @@ -56,7 +56,7 @@ ell" ┘ </pre> -<p>If <code><span class='Value'>𝕨</span></code> is too large it's usually not a problem. For Take, fill elements are added to the end to bring <code><span class='Value'>𝕩</span></code> up to the required length—although this <em>will</em> fail if <code><span class='Value'>𝕩</span></code> has no fill element. For Drop, the result is an empty array.</p> +<p>If <code><span class='Value'>𝕨</span></code> is too large it's usually not a problem. For Take, <a href="fill.html">fill elements</a> are added to the end to bring <code><span class='Value'>𝕩</span></code> up to the required length—although this <em>will</em> fail if <code><span class='Value'>𝕩</span></code> has no fill element. For Drop, the result is an empty array.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oaVNgoKMTAg4oaRIOKGlTYKCjEwIOKGkyDihpU2CgriiaIgNSDihpMg4oaVM+KAvznigL8y">↗️</a><pre> <span class='Function'>↕</span><span class='Number'>6</span> ⟨ 0 1 2 3 4 5 ⟩ diff --git a/docs/doc/types.html b/docs/doc/types.html index 297989c1..cef41290 100644 --- a/docs/doc/types.html +++ b/docs/doc/types.html @@ -43,7 +43,7 @@ </svg> <p>The reason operations and namespaces are called "mutable" is that the values obtained from them—by calling an operation on particular arguments or reading a field from a namespace—may change over the course of the program. This property is caused by variable modification <code><span class='Gets'>↩</span></code>, which can directly change a namespace field, or change the behavior of an operation that uses the modified variable. This means that a program that doesn't include <code><span class='Gets'>↩</span></code> won't have such changes in behavior. However, there will still be an observable difference between immutable data and the mutable types: code that creates a mutable value (for example, a block function <code><span class='Brace'>{</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code>) creates a different one each time, so that two different instances don't <a href="match.html">match</a> (<code><span class='Function'>≡</span></code>) each other. Data values created at different times may match, but mutable values never will.</p> -<p>An array is considered immutable because its shape, and what elements it contains, cannot change. An array has no identity outside these properties (and possibly its fill element), so an array with a different shape or different elements would simply be a different array. However, any element of an array could be mutable, in which case the behavior of the array would change with respect to the operation of selecting that element and calling it or accessing a field.</p> +<p>An array is considered immutable because its shape, and what elements it contains, cannot change. An array has no identity outside these properties (and possibly its <a href="fill.html">fill element</a>), so an array with a different shape or different elements would simply be a different array. However, any element of an array could be mutable, in which case the behavior of the array would change with respect to the operation of selecting that element and calling it or accessing a field.</p> <h2 id="data-types">Data types</h2> <p>Data types—numbers, characters, and arrays—are more like "things" than "actions". If called as a function, a value of one of these types simply returns itself. Data can be uniquely represented, compared for equality, and ordered using BQN's <a href="order.html#array-ordering">array ordering</a>; in contrast, determining whether two functions always return the same result can be undecidable. For arrays, these properties apply only if there are no operations inside. We might say that "data" in BQN refers to numbers, characters, and arrays of data.</p> <h3 id="numbers">Numbers</h3> |
