diff options
Diffstat (limited to 'spec/scope.md')
| -rw-r--r-- | spec/scope.md | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/spec/scope.md b/spec/scope.md index 4c2512e9..5c09bd1f 100644 --- a/spec/scope.md +++ b/spec/scope.md @@ -10,7 +10,7 @@ A running BQN program manipulates variables during its [execution](evaluate.md), 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 "same thing". In concrete terms, identifiers with the same definition all manipulate the same variable in a particular instance of the definition's containing scope. -A *scope* is a `PROGRAM`, `blSub`, `CASE`, `I_CASE`, or `A_CASE` node as defined by the BQN [grammar](grammar.md). An *identifier instance* is an `s`, `F`, `_m`, or `_c_` node (not including the special names that some block types allow for these terms); its *containing scope* is the "smallest" scope that contains it—the scope that contains the identifier but not any other scopes containing the identifier. An identifier instance is *defined* when it is contained in the left hand side of an `←` assignment expression, that is, the leftmost component of one of the four grammatical rules with `ASGN`, provided that the `ASGN` node is `"←"` or `"⇐"`, or in a scope header, that is, `IMM_HEAD`, `ARG_HEAD`, or the `s` term in `blSub`. Each identifier instance in a valid BQN program corresponds to exactly one such defined identifier, called its *definition*, and two instances are considered to refer to the same identifier if they have the same definition. +A *scope* is a `PROGRAM`, `blSub`, `CASE`, `I_CASE`, or `A_CASE` node as defined by the BQN [grammar](grammar.md). An *identifier instance* is an `s`, `F`, `_m`, or `_c_` node. This does not include the special names that some block types allow for these terms, and the names used only for namespace field access as [described below](#field-access-and-exports) are explicitly excluded. Its *containing scope* is the "smallest" scope that contains it—the scope that contains the identifier but not any other scopes containing the identifier. An identifier instance is *defined* when it is contained in the left hand side of an `←` assignment expression, that is, the leftmost component of one of the four grammatical rules with `ASGN`, provided that the `ASGN` node is `"←"` or `"⇐"`, or in a scope header, that is, `IMM_HEAD`, `ARG_HEAD`, or the `s` term in `blSub`. Each identifier instance in a valid BQN program corresponds to exactly one such defined identifier, called its *definition*, and two instances are considered to refer to the same identifier if they have the same definition. Two identifier instances have the *same name* if their tokens, as strings, match after removing all underscores `_` 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 *potential definition* of another identifier instance if the two have the same name, and either: - The defined identifier's containing scope contains the other identifier's containing scope, or @@ -28,9 +28,9 @@ Special names such as `𝕩` or `𝕣` refer to variables, but have no definitio The six special names are `𝕨𝕩𝕗𝕘𝕤𝕣`, and the tokens `𝕎𝕏𝔽𝔾𝕊`, `_𝕣`, and `_𝕣_` are alternate spellings of these names as described in the [tokenization rules](token.md). Special names may be modified with `↩` 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 `BODY` nodes that contains each is the same). The initial value these names have is defined by the [evaluation rules](evaluate.md); the grammar for blocks ensures that all special names used in a block will be defined (possibly as the special value `·` in the case of `𝕨`). For this reason special names in header rules `headW`, `headX`, `HeadF`, `HeadG`, and `LABEL` are defined to have no effect when evaluated. -### Imports and exports +### Field access and exports -Names that are preceded by an `atom "."` term, or that appear as `LHS_NAME` terms in an `NS_VAR` or `lhsNs`, are variable references in a namespace: in the first case, the result of the `atom` node, and in the second, of the overall assignments `subExpr` 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 `lhsNs`, or in `NS_VAR` with no accompanying `lhs "⇐"` term, additionally serves as an identifier within the actual enclosing scope, which works like any other assignment. +A name preceded by an `atom "."` term, and the `NAME` in `LHS_ENTRY`'s `lhs "⇐" NAME` rule, indicates a namespace *field access* and is excluded from being an identifier instance. Also, the `NAME` in an `LHS_ANY` may indicate a field access in addition to its role as an identifier declaration. A field access operates on a namespace, giving the value of a variable with a particular name in that namespace. It doesn't use lexical scoping; in general the name must be stored somehow in order to perform a lookup when the namespace is available. An identifier is *exported* if the `ASGN` node in its definition is `"⇐"`, or if it appears anywhere in an `EXPORT` term. An identifier can only be exported in the scope where it is defined, and not in a containing scope. An `EXPORT` term that includes an identifier from such a scope causes an error. |
