diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-10-02 21:29:30 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-10-02 21:29:30 -0400 |
| commit | 1518205cceeb1fef27c584d24e92b189ffd234f4 (patch) | |
| tree | 68c32dc9bf0cfc8634fee054d98a26b4e713e71e /docs/doc | |
| parent | 7f2cea6c9eef68fe2521508d87de7d37e6c0edbf (diff) | |
Grammar
Diffstat (limited to 'docs/doc')
| -rw-r--r-- | docs/doc/quick.html | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/docs/doc/quick.html b/docs/doc/quick.html index cbda94a9..5b7061a9 100644 --- a/docs/doc/quick.html +++ b/docs/doc/quick.html @@ -210,7 +210,7 @@ <p>First, <code><span class='Function'>Split</span></code> requires that the <a href="shape.html">rank</a> <code><span class='Function'>=</span><span class='Value'>π©</span></code> be 1, that is, <code><span class='Value'>π©</span></code> must be a list. In <code><span class='Number'>1</span><span class='Function'>==</span><span class='Value'>π©</span></code>, <code><span class='Function'>=</span></code> has two meanings, depending on whether it has a left argument. Next, it checks that each element has a character <a href="../spec/system.html#operation-properties">type</a>.</p> <p>The subexpression <code><span class='Function'>!</span><span class='Number'>2</span><span class='Function'>=β’Type</span></code> is a function <a href="train.html">train</a>, and it happens to have a simple expansion, as <code><span class='Paren'>(</span><span class='Function'>!</span><span class='Number'>2</span><span class='Function'>=β’Type</span><span class='Paren'>)</span><span class='Value'>e</span></code> is <code><span class='Function'>!</span><span class='Number'>2</span><span class='Function'>=β’Type</span> <span class='Value'>e</span></code>. It matters that <code><span class='Number'>2</span></code> is just a number; if it were a function it would be applied to <code><span class='Value'>e</span></code>. We'll discuss trains more later. This one is applied with <a href="map.html#one-argument-mapping">Each</a> to test every element of <code><span class='Value'>π©</span></code>. This does form an array result, but it's not used.</p> <h3 id="subfunction"><a class="header" href="#subfunction">Subfunction</a></h3> -<p>The function <code><span class='Function'>Proc</span></code> is called on each character of <code><span class='Value'>π©</span></code> along with the previous character, and says what to at that position. Also, it's deliberately inconsistent to cover more BQN features. Here's the whole thing:</p> +<p>The function <code><span class='Function'>Proc</span></code> is called on each character of <code><span class='Value'>π©</span></code> along with the previous character, and says what to do at that position. Also, it's deliberately inconsistent to cover more BQN features. Here's the whole thing:</p> <pre><span class='Function'>Proc</span> <span class='Gets'>β</span> <span class='Brace'>{</span> <span class='Nothing'>Β·</span> <span class='Function'>π</span> <span class='String'>' '</span><span class='Head'>:</span> <span class='Value'>spl</span><span class='Gets'>β</span><span class='Number'>1</span> <span class='Head'>;</span> <span class='Comment'># Space: break and delete it </span> <span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span><span class='Head'>:</span> <span class='Bracket'>β¨</span><span class='Value'>spl</span><span class='Separator'>,</span><span class='Value'>str</span><span class='Bracket'>β©</span><span class='Gets'>β</span> @@ -226,7 +226,7 @@ </pre> <p>This function has two bodies with <code><span class='Head'>;</span></code> in between. Each one has a <em>header</em>, separated from the body with a <code><span class='Head'>:</span></code>. A header indicates the kind of the block as a whole, and also which inputs the body after it works on. It mirrors the way the block should be used. In the right context, both <code><span class='Nothing'>Β·</span> <span class='Function'>π</span> <span class='String'>' '</span></code> and <code><span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span></code> would be valid function calls. Which tells us <code><span class='Function'>Proc</span></code> is a function.</p> <p>The first header, <code><span class='Nothing'>Β·</span> <span class='Function'>π</span> <span class='String'>' '</span><span class='Head'>:</span></code>, is more specific. The function is unlabelled, since <code><span class='Function'>π</span></code> just indicates the block function it's in (useful for <a href="block.html#self-reference">recursion</a>). The right argument is <code><span class='String'>' '</span></code>, a space character, so this body will only be used if <code><span class='Value'>π©</span></code> is a space. And the left argument isβ¦ <code><span class='Nothing'>Β·</span></code>, which is called <a href="expression.html#nothing">Nothing</a>. Both here and as an assignment target, Nothing indicates an ignored value. This body <em>does</em> require a left argument, but it doesn't name it. And the body itself is just <code><span class='Value'>spl</span><span class='Gets'>β</span><span class='Number'>1</span></code>. The <code><span class='Gets'>β</span></code> makes this body (only this one!) return a namespace, which has only the field <code><span class='Value'>spl</span></code>.</p> -<p>The next header, <code><span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span><span class='Head'>:</span></code> sets names for the function and its arguments, but doesn't constrain them other than requiring two arguments. So it applies in all the cases where the previous one didn't match, that is, when <code><span class='Value'>π©</span></code> isn't <code><span class='String'>' '</span></code>. The body starts with <code><span class='Bracket'>β¨</span><span class='Value'>spl</span><span class='Separator'>,</span><span class='Value'>str</span><span class='Bracket'>β©</span><span class='Gets'>β</span></code>, and the <code><span class='Gets'>β</span></code> means it will return a namespace too. This is an <a href="namespace.html#exports">export statement</a>, which declares <code><span class='Value'>spl</span></code> and <code><span class='Value'>str</span></code> to be fields but doesn't define themβthey must be defined somewhere else in the block, which is what happens next.</p> +<p>The next header, <code><span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span><span class='Head'>:</span></code>, sets names for the function and its arguments, but doesn't constrain them other than requiring two arguments. So it applies in all the cases where the previous one didn't match, that is, when <code><span class='Value'>π©</span></code> isn't <code><span class='String'>' '</span></code>. The body starts with <code><span class='Bracket'>β¨</span><span class='Value'>spl</span><span class='Separator'>,</span><span class='Value'>str</span><span class='Bracket'>β©</span><span class='Gets'>β</span></code>, and the <code><span class='Gets'>β</span></code> means it will return a namespace too. This is an <a href="namespace.html#exports">export statement</a>, which declares <code><span class='Value'>spl</span></code> and <code><span class='Value'>str</span></code> to be fields but doesn't define themβthey must be defined somewhere else in the block, which is what happens next.</p> <pre><span class='Value'>prev</span> <span class='Function'>Fn</span> <span class='Value'>cur</span><span class='Head'>:</span> <span class='Bracket'>β¨</span><span class='Value'>spl</span><span class='Separator'>,</span><span class='Value'>str</span><span class='Bracket'>β©</span><span class='Gets'>β</span> <span class='Value'>spl</span><span class='Gets'>β</span><span class='Number'>0</span> <span class='Separator'>β</span> <span class='Value'>str</span><span class='Gets'>β</span><span class='Bracket'>β¨</span><span class='Value'>cur</span><span class='Bracket'>β©</span> <span class='Comment'># Include and don't break... </span> <span class='Brace'>{</span> <span class='Value'>prev</span><span class='Function'>=</span><span class='Value'>cur</span> <span class='Head'>?</span> <span class='Value'>spl</span><span class='Function'>+</span><span class='Gets'>β©</span><span class='Number'>1</span> <span class='Head'>;</span> <span class='String'>@</span> <span class='Brace'>}</span> <span class='Comment'># except at equal characters @@ -240,7 +240,7 @@ <span class='Brace'>{</span><span class='Value'>π©.spl</span><span class='Brace'>}</span> <span class='Bracket'>β©</span> </pre> <p>Going left to right, <code><span class='Function'>GV</span><span class='Ligature'>βΏ</span><span class='Function'>GS</span></code> indicates <a href="expression.html#destructuring">destructuring assignment</a>, which will expect a list of two values on the right and take it apart to assign the two names. The right hand side is the function <code><span class='Brace'>{</span><span class='Function'>π</span><span class='Modifier'>Β¨</span><span class='Brace'>}</span><span class='Modifier'>Β¨</span></code> applied to a list.</p> -<p><code><span class='Brace'>{</span><span class='Function'>π</span><span class='Modifier'>Β¨</span><span class='Brace'>}</span></code> is a block function, like <code><span class='Function'>Split</span></code> but a lot shorter. It uses the uppercase <code><span class='Function'>π</span></code> instead of <code><span class='Value'>π©</span></code>, so that it treats <code><span class='Value'>π©</span></code> as a function (it doesn't <em>require</em> it to be a function, though: see <a href="context.html#mixing-roles">mixing roles</a>. It adds an Each <code><span class='Modifier'>Β¨</span></code> onto its argument. This is used to convert the two functions in the list from functions that work on a namespaces to functions that work on a list of them.</p> +<p><code><span class='Brace'>{</span><span class='Function'>π</span><span class='Modifier'>Β¨</span><span class='Brace'>}</span></code> is a block function, like <code><span class='Function'>Split</span></code> but a lot shorter. It uses the uppercase <code><span class='Function'>π</span></code> instead of <code><span class='Value'>π©</span></code>, so that it treats <code><span class='Value'>π©</span></code> as a function (it doesn't <em>require</em> it to be a function, though: see <a href="context.html#mixing-roles">mixing roles</a>). It adds an Each <code><span class='Modifier'>Β¨</span></code> onto its argument. This is used to convert the two functions in the list from functions that work on a namespaces to functions that work on a list of them.</p> <p>The list is split across two lines, using newline as a <a href="token.html#separators">separator</a> instead of <code><span class='Separator'>,</span></code> or <code><span class='Separator'>β</span></code>. Its second function <code><span class='Brace'>{</span><span class='Value'>π©.spl</span><span class='Brace'>}</span></code> is simpler: it takes a namespace <code><span class='Value'>π©</span></code> and gets the field named <code><span class='Value'>spl</span></code>.</p> <p>The first function is more complicated, because the argument namespace might or might not have an <code><span class='Value'>str</span></code> field. The list-like notation <code><span class='Bracket'>β¨</span><span class='Value'>s</span><span class='Gets'>β</span><span class='Value'>str</span><span class='Bracket'>β©</span></code> is another example of destructuring assignment, but this time it destructures a namespace, using an <a href="namespace.html#imports">alias</a> to give it a short name. This header leaves off the function name <code><span class='Function'>π</span></code>, using a <a href="block.html#case-headers">special rule</a> for one-argument functions. Arguments in headers are very similar to assignment targets, but if the destructuring doesn't match it tries the next body (if there is one) instead of giving an error. So if the argument is a namespace with an <code><span class='Value'>str</span></code> field then <code><span class='Brace'>{</span><span class='Bracket'>β¨</span><span class='Value'>s</span><span class='Gets'>β</span><span class='Value'>str</span><span class='Bracket'>β©</span><span class='Head'>:</span><span class='Value'>s</span><span class='Head'>;</span><span class='String'>""</span><span class='Brace'>}</span></code> returns that field's value, and otherwise it returns <code><span class='String'>""</span></code>.</p> <h3 id="assembly"><a class="header" href="#assembly">Assembly</a></h3> |
