aboutsummaryrefslogtreecommitdiff
path: root/docs/spec/scope.html
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-03-15 16:59:32 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-03-15 16:59:32 -0400
commit4f618598f2f31bc466343e4d304f35b53a366da6 (patch)
treef645f16425939a45ac82fcd0b3b477f9030bc7d9 /docs/spec/scope.html
parente858f41dffaee272ffcf4b2cb63a49ad25ebf7d7 (diff)
Finish namespace specification
Diffstat (limited to 'docs/spec/scope.html')
-rw-r--r--docs/spec/scope.html7
1 files changed, 4 insertions, 3 deletions
diff --git a/docs/spec/scope.html b/docs/spec/scope.html
index d5280e31..8ed5bab2 100644
--- a/docs/spec/scope.html
+++ b/docs/spec/scope.html
@@ -22,9 +22,10 @@
<p>Special names such as <code><span class='Value'>𝕩</span></code> or <code><span class='Value'>𝕣</span></code> refer to variables, but have no definition and do not use scoping. Instead, they always refer to the immediately enclosing scope, and are defined automatically when the block is evaluated.</p>
<p>The six special names are <code><span class='Value'>𝕨𝕩𝕗𝕘𝕤𝕣</span></code>, and the tokens <code><span class='Function'>𝕎𝕏𝔽𝔾𝕊</span></code>, <code><span class='Modifier'>_𝕣</span></code>, and <code><span class='Modifier2'>_𝕣_</span></code> are alternate spellings of these names as described in the <a href="token.html">tokenization rules</a>. Special names may be modified with <code><span class='Gets'>↩</span></code> assignment but cannot appear as the target of other kinds of assignment. Two special names represent the same identifier if they are the same name and appear in the same body. The initial value these names have is defined by the <a href="evaluate.html">evaluation rules</a>; the grammar for blocks ensures that all special names used in a block will be defined (possibly as the special value <code><span class='Nothing'>·</span></code> in the case of <code><span class='Value'>𝕨</span></code>).</p>
<h3 id="imports-and-exports">Imports and exports</h3>
-<p>The names to be used in an <code><span class='Function'>IMPORT</span></code>, that is, <code><span class='Function'>LHS_NAME</span></code> terms in an <code><span class='Function'>NS_VAR</span></code> or <code><span class='Value'>nsLHS</span></code>, are variable references inside that <code><span class='Function'>IMPORT</span></code>'s <code><span class='Value'>brNS</span></code> term. If they appear without an accompanying <code><span class='Value'>lhs</span> <span class='String'>&quot;⇐&quot;</span></code> term (in <code><span class='Function'>NS_VAR</span></code>), then this is in addition to their role as identifiers within the actual enclosing scope, which works like any other assignment. These references behave as though they are at the end of the <code><span class='Value'>brNS</span></code> term, that is, they &quot;see&quot; all definitions in the block. However, they must refer to identifiers that are <em>exported</em> by that block; references to any other variable cause an error much like references that have no definition.</p>
-<p>An identifier is exported if the <code><span class='Function'>ASGN</span></code> node in its definition is <code><span class='String'>&quot;⇐&quot;</span></code>, or if it appears anywhere in an <code><span class='Function'>EXPORT</span></code> term. An identifier can only be exported in the scope where it is defined, and not in a containing scope. An <code><span class='Function'>EXPORT</span></code> term that includes an identifier from such a scope causes an error.</p>
+<p>Names that are preceded by an <code><span class='Value'>atom</span> <span class='String'>&quot;.&quot;</span></code> term, or that appear as <code><span class='Function'>LHS_NAME</span></code> terms in an <code><span class='Function'>NS_VAR</span></code> or <code><span class='Value'>lhsNs</span></code>, are variable references in a namespace: in the first case, the result of the <code><span class='Value'>atom</span></code> node, and in the second, of the overall assignments <code><span class='Value'>subExpr</span></code> right hand side. These names do not follow lexical scoping; in general they must be stored in order to perform a name lookup when the namespace is available. Such a name in <code><span class='Value'>lhsNs</span></code>, or in <code><span class='Function'>NS_VAR</span></code> with no accompanying <code><span class='Value'>lhs</span> <span class='String'>&quot;⇐&quot;</span></code> term, additionally serves as an identifier within the actual enclosing scope, which works like any other assignment.</p>
+<p>An identifier is <em>exported</em> if the <code><span class='Function'>ASGN</span></code> node in its definition is <code><span class='String'>&quot;⇐&quot;</span></code>, or if it appears anywhere in an <code><span class='Function'>EXPORT</span></code> term. An identifier can only be exported in the scope where it is defined, and not in a containing scope. An <code><span class='Function'>EXPORT</span></code> term that includes an identifier from such a scope causes an error.</p>
<h2 id="variables">Variables</h2>
<p>A <em>variable</em> is an entity that permits two operations: it can be <em>set</em> to a particular value, and its <em>value</em> can be obtained, resulting in the last value it was set to. When either operation is performed it is referred to as <em>accessing</em> the variable.</p>
-<p>When a body in a block is evaluated, a variable is created for each definition (that is, defined identifier instance) the body contains. Whenever another block—the block itself, not its contents—is evaluated during the execution of the block, it is linked to the currently-evaluating block, so that it will use the variables defined in this instance. By following these links repeatedly, an instance of a block is always linked to exactly one instance of each block that contains it. These links form a tree that is not necessarily related to the call stack of functions and modifiers. Using the links, the variable an identifier refers to is the one corresponding to that variable's definition in the linked instance of the containing scope for the definition.</p>
+<p>When a body in a block is evaluated, it creates a <em>namespace</em>, which contains a variable for each definition (that is, defined identifier instance) the body contains. Whenever another block—the block itself, not its contents—is evaluated during the execution of the block, it is linked to the currently-evaluating block, so that it will use the variables defined in this instance. By following these links repeatedly, an instance of a block is always linked to exactly one instance of each block that contains it. These links form a tree that is not necessarily related to the call stack of functions and modifiers. Using the links, the variable an identifier refers to is the one corresponding to that variable's definition in the linked instance of the containing scope for the definition.</p>
<p>The first access to a variable must be made by its definition (this also means it sets the variable). If a different instance of its identifier accesses it first, then an error results. This can happen because every scope contained in a particular scope sees all the definitions it uses, and such a scope could be called before the definition is run. Because of conditional execution, this property must be checked at run time in general; however, in cases where it is possible to statically determine that a program will always violate it, a BQN instance can give an error at compile time rather than run time.</p>
+<p>A namespace defines a mapping from names to variables: if the given name is shared by an exported identifier in the body used to create that namespace, then that name maps to the variable corresponding to that identifier. The mapping is undefined for other names.</p>