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 | |
| parent | 7f2cea6c9eef68fe2521508d87de7d37e6c0edbf (diff) | |
Grammar
| -rw-r--r-- | doc/quick.md | 6 | ||||
| -rw-r--r-- | docs/doc/quick.html | 6 |
2 files changed, 6 insertions, 6 deletions
diff --git a/doc/quick.md b/doc/quick.md index 962216cc..fecee2a9 100644 --- a/doc/quick.md +++ b/doc/quick.md @@ -185,7 +185,7 @@ The subexpression `!2=•Type` is a function [train](train.md), and it happens t ### Subfunction -The function `Proc` is called on each character of `𝕩` 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: +The function `Proc` is called on each character of `𝕩` 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: Proc ← { · 𝕊 ' ': spl⇐1 ; # Space: break and delete it @@ -205,7 +205,7 @@ This function has two bodies with `;` in between. Each one has a *header*, separ The first header, `· 𝕊 ' ':`, is more specific. The function is unlabelled, since `𝕊` just indicates the block function it's in (useful for [recursion](block.md#self-reference)). The right argument is `' '`, a space character, so this body will only be used if `𝕩` is a space. And the left argument is… `·`, which is called [Nothing](expression.md#nothing). Both here and as an assignment target, Nothing indicates an ignored value. This body *does* require a left argument, but it doesn't name it. And the body itself is just `spl⇐1`. The `⇐` makes this body (only this one!) return a namespace, which has only the field `spl`. -The next header, `prev Fn cur:` 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 `𝕩` isn't `' '`. The body starts with `⟨spl,str⟩⇐`, and the `⇐` means it will return a namespace too. This is an [export statement](namespace.md#exports), which declares `spl` and `str` to be fields but doesn't define them—they must be defined somewhere else in the block, which is what happens next. +The next header, `prev Fn cur:`, 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 `𝕩` isn't `' '`. The body starts with `⟨spl,str⟩⇐`, and the `⇐` means it will return a namespace too. This is an [export statement](namespace.md#exports), which declares `spl` and `str` to be fields but doesn't define them—they must be defined somewhere else in the block, which is what happens next. prev Fn cur: ⟨spl,str⟩⇐ spl←0 ⋄ str←⟨cur⟩ # Include and don't break... @@ -226,7 +226,7 @@ Once `Proc` is applied to all the characters, we'll end up with a list of namesp Going left to right, `GV‿GS` indicates [destructuring assignment](expression.md#destructuring), 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 `{𝕏¨}¨` applied to a list. -`{𝕏¨}` is a block function, like `Split` but a lot shorter. It uses the uppercase `𝕏` instead of `𝕩`, so that it treats `𝕩` as a function (it doesn't *require* it to be a function, though: see [mixing roles](context.md#mixing-roles). It adds an Each `¨` 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. +`{𝕏¨}` is a block function, like `Split` but a lot shorter. It uses the uppercase `𝕏` instead of `𝕩`, so that it treats `𝕩` as a function (it doesn't *require* it to be a function, though: see [mixing roles](context.md#mixing-roles)). It adds an Each `¨` 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. The list is split across two lines, using newline as a [separator](token.md#separators) instead of `,` or `⋄`. Its second function `{𝕩.spl}` is simpler: it takes a namespace `𝕩` and gets the field named `spl`. 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> |
