aboutsummaryrefslogtreecommitdiff
path: root/docs/spec/scope.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/spec/scope.html')
-rw-r--r--docs/spec/scope.html4
1 files changed, 2 insertions, 2 deletions
diff --git a/docs/spec/scope.html b/docs/spec/scope.html
index 2a230ede..98375a8c 100644
--- a/docs/spec/scope.html
+++ b/docs/spec/scope.html
@@ -9,7 +9,7 @@
<p>A running BQN program manipulates variables during its <a href="evaluate.html">execution</a>, but it is important to distinguish these variables from the identifiers that refer to them. As defined in the <a href="token.html">tokenization rules</a>, an identifier is a particular kind of token found in a program's source code. The lexical scoping rules in this page define which identifiers are considered the same; these identifiers will refer to the same variables when the program is run. While each variable has only one identifier, an identifier can refer to any number of variables because a new variable is created for that identifier each time its containing scope is instantiated (that is, each time the contents of the block are evaluated).</p>
<h2 id="identifier-equivalence-with-lexical-scoping"><a class="header" href="#identifier-equivalence-with-lexical-scoping">Identifier equivalence with lexical scoping</a></h2>
<p>In this section the concept of an identifier's definition, a possibly different instance of that identifier, is specified. The definition determines when identifiers refer to the &quot;same thing&quot;. In concrete terms, identifiers with the same definition all manipulate the same variable in a particular instance of the definition's containing scope.</p>
-<p>A <em>scope</em> is a <code><span class='Function'>PROGRAM</span></code>, <code><span class='Value'>blSub</span></code>, <code><span class='Function'>CASE</span></code>, <code><span class='Function'>I_CASE</span></code>, or <code><span class='Function'>A_CASE</span></code> node as defined by the BQN <a href="grammar.html">grammar</a>. An <em>identifier instance</em> is an <code><span class='Value'>s</span></code>, <code><span class='Function'>F</span></code>, <code><span class='Modifier'>_m</span></code>, or <code><span class='Modifier2'>_c_</span></code> node; its <em>containing scope</em> is the &quot;smallest&quot; scope that contains it—the scope that contains the identifier but not any other scopes containing the identifier. An identifier instance is <em>defined</em> when it is contained in the left hand side of an <code><span class='Gets'>←</span></code> assignment expression, that is, the leftmost component of one of the four grammatical rules with <code><span class='Function'>ASGN</span></code>, provided that the <code><span class='Function'>ASGN</span></code> node is <code><span class='String'>&quot;←&quot;</span></code> or <code><span class='String'>&quot;⇐&quot;</span></code>, or in a scope header, that is, <code><span class='Function'>IMM_HEAD</span></code>, <code><span class='Function'>ARG_HEAD</span></code>, or the <code><span class='Value'>s</span></code> term in <code><span class='Value'>blSub</span></code>. Each identifier instance in a valid BQN program corresponds to exactly one such defined identifier, called its <em>definition</em>, and two instances are considered to refer to the same identifier if they have the same definition.</p>
+<p>A <em>scope</em> is a <code><span class='Function'>PROGRAM</span></code>, <code><span class='Value'>blSub</span></code>, <code><span class='Function'>CASE</span></code>, <code><span class='Function'>I_CASE</span></code>, or <code><span class='Function'>A_CASE</span></code> node as defined by the BQN <a href="grammar.html">grammar</a>. An <em>identifier instance</em> is an <code><span class='Value'>s</span></code>, <code><span class='Function'>F</span></code>, <code><span class='Modifier'>_m</span></code>, or <code><span class='Modifier2'>_c_</span></code> node (not including the special names that some block types allow for these terms); its <em>containing scope</em> is the &quot;smallest&quot; scope that contains it—the scope that contains the identifier but not any other scopes containing the identifier. An identifier instance is <em>defined</em> when it is contained in the left hand side of an <code><span class='Gets'>←</span></code> assignment expression, that is, the leftmost component of one of the four grammatical rules with <code><span class='Function'>ASGN</span></code>, provided that the <code><span class='Function'>ASGN</span></code> node is <code><span class='String'>&quot;←&quot;</span></code> or <code><span class='String'>&quot;⇐&quot;</span></code>, or in a scope header, that is, <code><span class='Function'>IMM_HEAD</span></code>, <code><span class='Function'>ARG_HEAD</span></code>, or the <code><span class='Value'>s</span></code> term in <code><span class='Value'>blSub</span></code>. Each identifier instance in a valid BQN program corresponds to exactly one such defined identifier, called its <em>definition</em>, and two instances are considered to refer to the same identifier if they have the same definition.</p>
<p>Two identifier instances have the <em>same name</em> if their tokens, as strings, match after removing all underscores <code><span class='Modifier2'>_</span></code> and ignoring case (so that the letters a to z are equal to their uppercase equivalents A to Z for this comparison). However, instances with the same name are not necessarily the same identifier, as they must also have the same definition. A defined identifier is a <em>potential definition</em> of another identifier instance if the two have the same name, and either:</p>
<ul>
<li>The defined identifier's containing scope contains the other identifier's containing scope, or</li>
@@ -21,7 +21,7 @@
<p>A subject label is the <code><span class='Value'>s</span></code> term in a <code><span class='Value'>blSub</span></code> node. As part of a header, it can serve as the definition for an identifier. However, it's defined to be a syntax error if another instance of this identifier appears.</p>
<h3 id="special-names"><a class="header" href="#special-names">Special names</a></h3>
<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 (more precisely, the set of <code><span class='Function'>BODY</span></code> nodes that contains each is the same). 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>
+<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 (more precisely, the set of <code><span class='Function'>BODY</span></code> nodes that contains each is the same). 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>). For this reason special names in header rules <code><span class='Value'>headW</span></code>, <code><span class='Value'>headX</span></code>, <code><span class='Function'>HeadF</span></code>, <code><span class='Function'>HeadG</span></code>, and <code><span class='Function'>LABEL</span></code> are defined to have no effect when evaluated.</p>
<h3 id="imports-and-exports"><a class="header" href="#imports-and-exports">Imports and exports</a></h3>
<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>