From 2abb2a9ea25bfa4065eb374d1e2ff9d3669b75f4 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 9 Oct 2020 10:15:31 -0400 Subject: =?UTF-8?q?Add=20=E2=87=90=20to=20syntax=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/syntax.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'doc/syntax.md') 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 -- cgit v1.2.3