aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2022-11-18 22:10:59 -0500
committerMarshall Lochbaum <mwlochbaum@gmail.com>2022-11-18 22:10:59 -0500
commite7f09d54e76d61709763dcaf1b3081812d88fe46 (patch)
treedb3a336c207bbfd34bf09e8e2f1ea2ccfa12e7e2
parente42111e4dfc2fac9f99b053fd3cd65cd6e11259f (diff)
Move introduction of the optional-function rule to main header section, not multiple bodies
-rw-r--r--doc/block.md4
-rw-r--r--doc/quick.md2
-rw-r--r--docs/doc/block.html3
-rw-r--r--docs/doc/quick.html2
4 files changed, 7 insertions, 4 deletions
diff --git a/doc/block.md b/doc/block.md
index e4d32fa4..9e436490 100644
--- a/doc/block.md
+++ b/doc/block.md
@@ -157,6 +157,8 @@ Any element of a function or modifier header can be left nameless by using the c
The name `𝕨` in this context can refer to either a left argument or no left argument, allowing a header with arguments to be used even for an ambiguous function. Recall that `𝕨` is the only token other than `Β·` that can have no value. If an identifier or list is given as the left argument, then the function must be called with a left argument.
+If a header consists of `π•Š` with one argument, like `π•Š aβ€Ώb:` or `π•Šπ•©:`, the `π•Š` can be left off. See [case headers](#case-headers) below for examples. The exception is if the argument is a plain name, as in `π•Š arg:`, because the header `arg:` is a label for an immediate block as described in the next section.
+
### Short headers
A header can also be a plain name with no inputs, called a *label*. A label specifies the type of the block and gives an internal name that can be used to refer to it, but doesn't specify the inputs.
@@ -198,7 +200,7 @@ If no header is compatible, the call results in an error.
### Case headers
-A special rule allows for convenient case-matching syntax for one-argument functions. In any function header with one argument, the function name can be omitted as long as the argument is *not* a plain identifierβ€”it must be `𝕩` or a compound value like a list to distinguish it from an immediate block label.
+The optional `π•Š` rule makes for convenient case-matching syntax in one-argument functions.
Test ← {
"abc": "string" ;
diff --git a/doc/quick.md b/doc/quick.md
index fecee2a9..afb89519 100644
--- a/doc/quick.md
+++ b/doc/quick.md
@@ -230,7 +230,7 @@ Going left to right, `GVβ€ΏGS` indicates [destructuring assignment](expression.m
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`.
-The first function is more complicated, because the argument namespace might or might not have an `str` field. The list-like notation `⟨s⇐str⟩` is another example of destructuring assignment, but this time it destructures a namespace, using an [alias](namespace.md#imports) to give it a short name. This header leaves off the function name `π•Š`, using a [special rule](block.md#case-headers) 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 `str` field then `{⟨s⇐str⟩:s;""}` returns that field's value, and otherwise it returns `""`.
+The first function is more complicated, because the argument namespace might or might not have an `str` field. The list-like notation `⟨s⇐str⟩` is another example of destructuring assignment, but this time it destructures a namespace, using an [alias](namespace.md#imports) to give it a short name. This header leaves off the function name `π•Š`, using a [special rule](block.md#special-names-in-headers) 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 `str` field then `{⟨s⇐str⟩:s;""}` returns that field's value, and otherwise it returns `""`.
### Assembly
diff --git a/docs/doc/block.html b/docs/doc/block.html
index cfffe895..115f47ec 100644
--- a/docs/doc/block.html
+++ b/docs/doc/block.html
@@ -184,6 +184,7 @@
<h3 id="special-names-in-headers"><a class="header" href="#special-names-in-headers">Special names in headers</a></h3>
<p>Any element of a function or modifier header can be left nameless by using the corresponding special name in that position, instead of an identifier. For example, the header <code><span class='Value'>𝕨</span> <span class='Function'>𝔽</span><span class='Modifier2'>_𝕣_</span><span class='Function'>𝔾</span> <span class='Value'>𝕩</span><span class='Head'>:</span></code> incorporates as much vagueness as possible. It indicates a deferred 2-modifier, but provides no other information.</p>
<p>The name <code><span class='Value'>𝕨</span></code> in this context can refer to either a left argument or no left argument, allowing a header with arguments to be used even for an ambiguous function. Recall that <code><span class='Value'>𝕨</span></code> is the only token other than <code><span class='Nothing'>Β·</span></code> that can have no value. If an identifier or list is given as the left argument, then the function must be called with a left argument.</p>
+<p>If a header consists of <code><span class='Function'>π•Š</span></code> with one argument, like <code><span class='Function'>π•Š</span> <span class='Value'>a</span><span class='Ligature'>β€Ώ</span><span class='Value'>b</span><span class='Head'>:</span></code> or <code><span class='Function'>π•Š</span><span class='Value'>𝕩</span><span class='Head'>:</span></code>, the <code><span class='Function'>π•Š</span></code> can be left off. See <a href="#case-headers">case headers</a> below for examples. The exception is if the argument is a plain name, as in <code><span class='Function'>π•Š</span> <span class='Value'>arg</span><span class='Head'>:</span></code>, because the header <code><span class='Value'>arg</span><span class='Head'>:</span></code> is a label for an immediate block as described in the next section.</p>
<h3 id="short-headers"><a class="header" href="#short-headers">Short headers</a></h3>
<p>A header can also be a plain name with no inputs, called a <em>label</em>. A label specifies the type of the block and gives an internal name that can be used to refer to it, but doesn't specify the inputs.</p>
<pre><span class='Brace'>{</span> <span class='Value'>b</span><span class='Head'>:</span> <span class='Comment'># Block
@@ -223,7 +224,7 @@
<span class='Error'>Error: No header matched arguments</span>
</pre>
<h3 id="case-headers"><a class="header" href="#case-headers">Case headers</a></h3>
-<p>A special rule allows for convenient case-matching syntax for one-argument functions. In any function header with one argument, the function name can be omitted as long as the argument is <em>not</em> a plain identifierβ€”it must be <code><span class='Value'>𝕩</span></code> or a compound value like a list to distinguish it from an immediate block label.</p>
+<p>The optional <code><span class='Function'>π•Š</span></code> rule makes for convenient case-matching syntax in one-argument functions.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=YeKGkGLihpAib3V0ZXIiClRlc3Qg4oaQIHsKICAiYWJjIjogInN0cmluZyIgOwogIOKfqDIsYuKfqTog4oy98J2VqSAgICAgICA7CiAgNTogICAgICJudW1iZXIiIDsKICDwnZWpOiAgICAgImRlZmF1bHQiCn0KVGVzdCA1">↗️</a><pre> <span class='Function'>Test</span> <span class='Gets'>←</span> <span class='Brace'>{</span>
<span class='String'>&quot;abc&quot;</span><span class='Head'>:</span> <span class='String'>&quot;string&quot;</span> <span class='Head'>;</span>
<span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Value'>b</span><span class='Bracket'>⟩</span><span class='Head'>:</span> <span class='Function'>⌽</span><span class='Value'>𝕩</span> <span class='Head'>;</span>
diff --git a/docs/doc/quick.html b/docs/doc/quick.html
index 5b7061a9..64eefcd7 100644
--- a/docs/doc/quick.html
+++ b/docs/doc/quick.html
@@ -242,7 +242,7 @@
<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>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'>&quot;&quot;</span><span class='Brace'>}</span></code> returns that field's value, and otherwise it returns <code><span class='String'>&quot;&quot;</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#special-names-in-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'>&quot;&quot;</span><span class='Brace'>}</span></code> returns that field's value, and otherwise it returns <code><span class='String'>&quot;&quot;</span></code>.</p>
<h3 id="assembly"><a class="header" href="#assembly">Assembly</a></h3>
<p>Now that <code><span class='Function'>Split</span></code> has defined <code><span class='Function'>Proc</span></code>, <code><span class='Function'>GV</span></code> (get value), and <code><span class='Function'>GS</span></code> (get split), it's ready to do its work.</p>
<pre><span class='Value'>r</span> <span class='Gets'>←</span> <span class='Function'>Proc</span><span class='Brace'>{</span><span class='Function'>»𝔽</span><span class='Modifier'>Β¨</span><span class='Function'>⊒</span><span class='Brace'>}</span> <span class='Value'>𝕩</span>