From 8038e6f0fd5d8f0b4f2eb6d685eb42b8f14c6cd9 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 3 Dec 2021 22:04:44 -0500 Subject: Update scoping spec: field accesses instead of import statements --- docs/spec/scope.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs') diff --git a/docs/spec/scope.html b/docs/spec/scope.html index 98375a8c..f5e3e2c8 100644 --- a/docs/spec/scope.html +++ b/docs/spec/scope.html @@ -9,7 +9,7 @@

A running BQN program manipulates variables during its execution, but it is important to distinguish these variables from the identifiers that refer to them. As defined in the tokenization rules, 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).

Identifier equivalence with lexical scoping

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. 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. 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 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: