From 916398d2a08c01c684f27b2fce44ff96a6d97e48 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 3 Dec 2021 21:43:21 -0500 Subject: Clarifications about special names --- docs/spec/scope.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs') 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 @@

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; 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 (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.

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: