diff options
Diffstat (limited to 'docs/doc')
| -rw-r--r-- | docs/doc/syntax.html | 14 |
1 files changed, 14 insertions, 0 deletions
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'>"str"</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> |
