aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/syntax.md14
-rw-r--r--docs/doc/syntax.html14
-rw-r--r--docs/spec/token.html2
-rw-r--r--spec/token.md2
4 files changed, 30 insertions, 2 deletions
diff --git a/doc/syntax.md b/doc/syntax.md
index c74c3b2f..3fedee42 100644
--- a/doc/syntax.md
+++ b/doc/syntax.md
@@ -16,6 +16,7 @@ Glyph(s) | Meaning
`¯∞π` | [Used in numeric literals](#constants)
`()` | Expression grouping
`←` | [Define](#assignment)
+`⇐` | [Export](#exports)
`↩` | [Change](#assignment)
`→` | [Return](block.md#returns)
`⋄,` or newline | Statement or element [separator](#separators)
@@ -81,6 +82,19 @@ Assignment can be used inline in an expression, and its result is always the val
2×a←(Neg←-)3
a
+### Exports
+
+The double arrow `⇐` is used to export variables from an immediate block or file. It can only be used in these contexts, and not in function or modifier blocks. There are two ways to export variables. First, `←` in the variable definition can be replaced with `⇐` to export the variable as it's defined. Second, an export statement consisting of an assignment target followed by `⇐` with nothing to the right exports the variables in the assignment target and does nothing else. Export statements can be placed anywhere in the relevant program or body, including before declaration or on the last line, and a given variable can be exported any number of times.
+
+ ⟨a:alias, b, c:c0‿c1, b:b2⟩←{
+ b‿c⇐ # Non-definition exports can go anywhere
+ a⇐2 # Define and export
+ b←1+a
+ c←b‿"str"
+ }
+
+A block with exports is a *namespace block*, and in versions of BQN without first-class namespaces it can only be used as part of a destructuring assignment. This assignment's target is a list where each element specifies one of the names exported by the block and what it should be assigned to. The element can be either a single name (such as `b` above), which gives both, or a combination of a name, then `:`, then the assignment target. If `:` is never used, the names can be given as a strand with `‿`. To use `:` for aliases, bracket syntax `⟨⟩` is needed. Imported names can be repeated and can be spelled with any role (the role is ignored).
+
## Lists and blocks
### Separators
diff --git a/docs/doc/syntax.html b/docs/doc/syntax.html
index 0a6aab58..df063677 100644
--- a/docs/doc/syntax.html
+++ b/docs/doc/syntax.html
@@ -41,6 +41,10 @@
<td><a href="#assignment">Define</a></td>
</tr>
<tr>
+<td><code><span class='Gets'>⇐</span></code></td>
+<td><a href="#exports">Export</a></td>
+</tr>
+<tr>
<td><code><span class='Gets'>↩</span></code></td>
<td><a href="#assignment">Change</a></td>
</tr>
@@ -145,6 +149,16 @@
<span class='Value'>a</span>
¯3
</pre>
+<h3 id="exports">Exports</h3>
+<p>The double arrow <code><span class='Gets'>⇐</span></code> is used to export variables from an immediate block or file. It can only be used in these contexts, and not in function or modifier blocks. There are two ways to export variables. First, <code><span class='Gets'>←</span></code> in the variable definition can be replaced with <code><span class='Gets'>⇐</span></code> to export the variable as it's defined. Second, an export statement consisting of an assignment target followed by <code><span class='Gets'>⇐</span></code> with nothing to the right exports the variables in the assignment target and does nothing else. Export statements can be placed anywhere in the relevant program or body, including before declaration or on the last line, and a given variable can be exported any number of times.</p>
+<pre><span class='Bracket'>⟨</span><span class='Value'>a:alias</span><span class='Separator'>,</span> <span class='Value'>b</span><span class='Separator'>,</span> <span class='Value'>c:c0</span><span class='Ligature'>‿</span><span class='Value'>c1</span><span class='Separator'>,</span> <span class='Value'>b:b2</span><span class='Bracket'>⟩</span><span class='Gets'>←</span><span class='Brace'>{</span>
+ <span class='Value'>b</span><span class='Ligature'>‿</span><span class='Value'>c</span><span class='Gets'>⇐</span> <span class='Comment'># Non-definition exports can go anywhere
+</span> <span class='Value'>a</span><span class='Gets'>⇐</span><span class='Number'>2</span> <span class='Comment'># Define and export
+</span> <span class='Value'>b</span><span class='Gets'>←</span><span class='Number'>1</span><span class='Function'>+</span><span class='Value'>a</span>
+ <span class='Value'>c</span><span class='Gets'>←</span><span class='Value'>b</span><span class='Ligature'>‿</span><span class='String'>&quot;str&quot;</span>
+<span class='Brace'>}</span>
+</pre>
+<p>A block with exports is a <em>namespace block</em>, and in versions of BQN without first-class namespaces it can only be used as part of a destructuring assignment. This assignment's target is a list where each element specifies one of the names exported by the block and what it should be assigned to. The element can be either a single name (such as <code><span class='Value'>b</span></code> above), which gives both, or a combination of a name, then <code><span class='Value'>:</span></code>, then the assignment target. If <code><span class='Value'>:</span></code> is never used, the names can be given as a strand with <code><span class='Ligature'>‿</span></code>. To use <code><span class='Value'>:</span></code> for aliases, bracket syntax <code><span class='Bracket'>⟨⟩</span></code> is needed. Imported names can be repeated and can be spelled with any role (the role is ignored).</p>
<h2 id="lists-and-blocks">Lists and blocks</h2>
<h3 id="separators">Separators</h3>
<p>The characters <code><span class='Separator'>⋄</span></code> and <code><span class='Separator'>,</span></code> and newline are completely interchangeable and are used to separate expressions. An expression might be an element in a list or a line in a function. Empty sections—those that consist only of whitespace—are ignored. This means that any number of separators can be used between expressions, and that leading and trailing separators are also allowed. The expressions are evaluated in text order: left to right and top to bottom.</p>
diff --git a/docs/spec/token.html b/docs/spec/token.html
index b39b524d..9ad2c79f 100644
--- a/docs/spec/token.html
+++ b/docs/spec/token.html
@@ -42,7 +42,7 @@
</tr>
<tr>
<td>Punctuation</td>
-<td><code><span class='Gets'>←↩→</span><span class='Paren'>()</span><span class='Brace'>{}</span><span class='Bracket'>⟨⟩</span><span class='Ligature'>‿</span><span class='Separator'>⋄,</span></code> and newline</td>
+<td><code><span class='Gets'>←⇐↩→</span><span class='Paren'>()</span><span class='Brace'>{}</span><span class='Bracket'>⟨⟩</span><span class='Ligature'>‿</span><span class='Separator'>⋄,</span></code> and newline</td>
</tr>
</tbody>
</table>
diff --git a/spec/token.md b/spec/token.md
index e7e67324..fb1bb3c6 100644
--- a/spec/token.md
+++ b/spec/token.md
@@ -23,6 +23,6 @@ Otherwise, a single character forms a token. Only the specified set of character
| Primitive 1-Modifier | `` ˙˜˘¨⌜⁼´˝` ``
| Primitive 1-Modifier | `∘○⊸⟜⌾⊘◶⎉⚇⍟`
| Special name | `𝕨𝕩𝕗𝕘𝕤𝕎𝕏𝔽𝔾𝕊`
-| Punctuation | `←↩→(){}⟨⟩‿⋄,` and newline
+| Punctuation | `←⇐↩→(){}⟨⟩‿⋄,` and newline
In the BQN [grammar specification](grammar.md), the three primitive classes are grouped into terminals `Fl`, `_ml`, and `_cl`, while the punctuation characters are identified separately as keywords such as `"←"`. The special names are handled specially. The uppercase versions `𝕎𝕏𝔽𝔾𝕊` and lowercase versions `𝕨𝕩𝕗𝕘𝕤` are two spellings of the five underlying inputs and function.