diff options
Diffstat (limited to 'docs/doc/search.html')
| -rw-r--r-- | docs/doc/search.html | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/docs/doc/search.html b/docs/doc/search.html index 2e75dc97..a92b25c1 100644 --- a/docs/doc/search.html +++ b/docs/doc/search.html @@ -89,7 +89,7 @@ </g> </svg> -<p>The three search functions are Index of (<code><span class='Function'>β</span></code>), Progressive Index of (<code><span class='Function'>β</span></code>), and Member of (<code><span class='Function'>β</span></code>). These are dyadic functions that search one argument ("searched-in") for major cells <a href="match.html">matching</a> cells from the other ("searched-for"). For example, Index of returns, for each cell in <code><span class='Value'>π©</span></code>, the index of the first cell in <code><span class='Value'>π¨</span></code> that matches it.</p> +<p>The three search functions are Index of (<code><span class='Function'>β</span></code>), Progressive Index of (<code><span class='Function'>β</span></code>), and Member of (<code><span class='Function'>β</span></code>). These are dyadic functions that search one argument ("searched-in") for major cells <a href="match.html">matching</a> cells from the other ("searched-for"). For example, Index of returns, for each <a href="array.html#cells">cell</a> in <code><span class='Value'>π©</span></code>, the index of the first cell in <code><span class='Value'>π¨</span></code> that matches it.</p> <table> <thead> <tr> @@ -153,7 +153,7 @@ β¨ 1 4 2 β© </pre> <p><code><span class='Value'>π©</span><span class='Function'>β</span><span class='Value'>π¨</span></code> is the same as <code><span class='Paren'>(</span><span class='Value'>π¨</span><span class='Function'>β</span><span class='Value'>π©</span><span class='Paren'>)</span><span class='Function'><β </span><span class='Value'>π¨</span></code>. Note the reversal of arguments! In both <code><span class='Function'>β</span></code> and <code><span class='Function'>β</span></code>, the open side points to the searched-in argument and the closed side points to the searched-for argument. Relatedly, in Select (<code><span class='Function'>β</span></code>), the open side points to the selected argument, which is more like the searched-in argument in that its cells are generally accessed out of order (the searched-for argument is most like the selection result <code><span class='Value'>π¨</span><span class='Function'>β</span><span class='Value'>π©</span></code>).</p> -<p>Index of always returns exactly one number, even if there are multiple matches, or no matches at all. To find the indices of all matches, start with <a href="match.html">Match</a> <a href="map.html">Each</a>, then <a href="replicate.html#indices">Indices</a> (I didn't mean for it to sound so repetitive! It just happened!).</p> +<p>Index of always returns exactly one number, even if there are multiple matches, or no matches at all. To find the indices of all matches, start with <a href="match.html">Match</a> <a href="map.html">Each</a>, then apply <a href="replicate.html#indices">Indices</a> (I didn't mean for it to sound so repetitive! It just happened!).</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=LyAibGV0dGVycyIg4omhwqg8ICdlJyAgICAgICAgIyBNYW55IHRvIG9uZQoKImxldHRlcnMiICg84oiYL8uY4omh4oycy5wpICJsZXQiICAjIE1hbnkgdG8gbWFueQ==">βοΈ</a><pre> <span class='Function'>/</span> <span class='String'>"letters"</span> <span class='Function'>β‘</span><span class='Modifier'>Β¨</span><span class='Function'><</span> <span class='String'>'e'</span> <span class='Comment'># Many to one </span>β¨ 1 4 β© @@ -161,7 +161,7 @@ </span>β¨ β¨ 0 β© β¨ 1 4 β© β¨ 2 3 β© β© </pre> <h2 id="progressive-index-of"><a class="header" href="#progressive-index-of">Progressive Index of</a></h2> -<p>Progressive Index of (<code><span class='Function'>β</span></code>), as the name and glyph suggest, is a more sophisticated variant of Index of. Like Index of, it returns either <code><span class='Function'>β </span><span class='Value'>π¨</span></code> or an index of a cell from <code><span class='Value'>π¨</span></code> that matches the given cell of <code><span class='Value'>π©</span></code>. Unlike Index of, no index except <code><span class='Function'>β </span><span class='Value'>π¨</span></code> can ever be repeated. Progressive Index of returns the index of the first <em>unused</em> match, provided there's still one left.</p> +<p>Progressive Index of (<code><span class='Function'>β</span></code>), as the name and glyph suggest, is a more sophisticated variant of Index of. Like Index of, it returns either <code><span class='Function'>β </span><span class='Value'>π¨</span></code> or an index of a cell from <code><span class='Value'>π¨</span></code> that matches the given cell of <code><span class='Value'>π©</span></code>. Unlike Index of, no index can ever be repeated (but <code><span class='Function'>β </span><span class='Value'>π¨</span></code> can). Progressive Index of returns the index of the first <em>unused</em> match, provided there's still one left.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=ImFhYSIg4oqSICJhYWFhYSIKCiJhYWFiYiIg4oqSICJhYmFiYWJhYmFiIg==">βοΈ</a><pre> <span class='String'>"aaa"</span> <span class='Function'>β</span> <span class='String'>"aaaaa"</span> β¨ 0 1 2 3 3 β© @@ -209,7 +209,7 @@ Β· 2 β </pre> -<p>Just as bad, this result has the right information, but is enclosed and could break the program later on. Remember that the result of a search function is <em>always</em> an array. We really want the <a href="pick.html#first">first</a> element.</p> +<p>This result has the right information, but is enclosed and could break the program later on. Remember that the result of a search function is <em>always</em> an array. We really want the <a href="pick.html#first">first</a> element.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=c3R1ZmYg4oqR4oiY4oqQ4p+cPCAic3RyaW5nIg==">βοΈ</a><pre> <span class='Value'>stuff</span> <span class='Function'>β</span><span class='Modifier2'>β</span><span class='Function'>β</span><span class='Modifier2'>β</span><span class='Function'><</span> <span class='String'>"string"</span> 2 </pre> @@ -235,7 +235,7 @@ β </pre> <p>But the searched-in argument doesn't have to be a list either! It can also be an array of higher rank. Rank 0 isn't allowed: if you want to "search" a unit, you're probably just looking for <a href="match.html">match</a>.</p> -<p>The searched-in argument is treated as a list of its major cells. It's the rank of these major cellsβlet's call this rank <code><span class='Value'>c</span></code>βthat determines how the searched-for argument is treated. That argument must have rank <code><span class='Value'>c</span></code> or more, and it's treated as an array of <code><span class='Value'>c</span></code>-cells. For example, if the left argument to <code><span class='Function'>β</span></code> is a rank-2 table, then each 1-cell (row) of <code><span class='Value'>π©</span></code> is searched for independently, yielding one number in the result: a 0-cell.</p> +<p>The searched-in argument is treated as a list of its <a href="array.html#cells">major cells</a>. It's the rank of these major cellsβlet's call this rank <code><span class='Value'>c</span></code>βthat determines how the searched-for argument is treated. That argument must have rank <code><span class='Value'>c</span></code> or more, and it's treated as an array of <code><span class='Value'>c</span></code>-cells. For example, if the left argument to <code><span class='Function'>β</span></code> is a rank-2 table, then each 1-cell (row) of <code><span class='Value'>π©</span></code> is searched for independently, yielding one number in the result: a 0-cell.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oqiIHJvd3Mg4oaQID4icm93IuKAvyJyaG8i4oC/InJvdyLigL8icnVlIgoKcm93cyDiipAgPiJyb3ci4oC/InJvdyLigL8iY29sIuKJjSJyaG8i4oC/ImNvdyLigL8iY29sIg==">βοΈ</a><pre> <span class='Function'>β’</span> <span class='Value'>rows</span> <span class='Gets'>β</span> <span class='Function'>></span><span class='String'>"row"</span><span class='Ligature'>βΏ</span><span class='String'>"rho"</span><span class='Ligature'>βΏ</span><span class='String'>"row"</span><span class='Ligature'>βΏ</span><span class='String'>"rue"</span> ββ β΅"row @@ -251,7 +251,7 @@ β </pre> <p>So the result rank of <code><span class='Function'>β</span></code> is always <code><span class='Value'>π¨</span><span class='Function'>Β¬</span><span class='Modifier2'>β</span><span class='Function'>=</span><span class='Value'>π©</span></code>, with a result shape <code><span class='Paren'>(</span><span class='Number'>1</span><span class='Function'>-</span><span class='Modifier'>Λ</span><span class='Function'>=</span><span class='Value'>π¨</span><span class='Paren'>)</span><span class='Function'>ββ’</span><span class='Value'>π©</span></code>, and <code><span class='Value'>π¨</span><span class='Function'>β</span><span class='Value'>π©</span></code> fails if <code><span class='Number'>1</span><span class='Function'>>=</span><span class='Value'>π©</span></code> or the result rank would be negative. In the list case, we have <code><span class='Number'>1</span><span class='Function'>==</span><span class='Value'>π©</span></code> (so the first condition holds), and the result rank resolves to <code><span class='Function'>=</span><span class='Value'>π¨</span></code> (which can't be negative, so the second holds as well). The cell rank of <code><span class='Value'>π©</span></code> is 0, and the fact that a 0-cell of <code><span class='Value'>π©</span></code> gives a 0-cell of the result is what causes the shape arithmetic to be so simple.</p> -<p>For Member of, the arguments are reversed relative to Index of, but otherwise everything's the same. This differs from APL, where entries are always elements, not cells. Many APL designers consider the APL definition to be a failure of foresight and would prefer BQN's definitionβor rather A+'s or J's definition, as these languages were actually the first to use it. The rank-aware version is more flexible, as it allows both searching for elements and searching for rows. APL would return the first result in both cases.</p> +<p>For Member of, the arguments are reversed relative to Index of, but otherwise everything's the same. This differs from APL, where entries are always elements, not cells. Many APL designers consider the APL definition to be a failure of foresight and would prefer BQN's definitionβor rather A+'s or J's definition, as these languages were actually the first to use it. The rank-aware version is more flexible, as it allows both searching for elements and searching for rows. APL would return the first result in both cases below.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KDLigL8x4omNM+KAvzEpIOKIiiAz4oC/MeKAvzTigL8zCgooMuKAvzHiiY0z4oC/MSkg4oiKIDPigL8x4omNNOKAvzM=">βοΈ</a><pre> <span class='Paren'>(</span><span class='Number'>2</span><span class='Ligature'>βΏ</span><span class='Number'>1</span><span class='Function'>β</span><span class='Number'>3</span><span class='Ligature'>βΏ</span><span class='Number'>1</span><span class='Paren'>)</span> <span class='Function'>β</span> <span class='Number'>3</span><span class='Ligature'>βΏ</span><span class='Number'>1</span><span class='Ligature'>βΏ</span><span class='Number'>4</span><span class='Ligature'>βΏ</span><span class='Number'>3</span> ββ β΅ 0 1 |
