diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-10-12 21:57:46 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-10-12 22:05:53 -0400 |
| commit | cebb1bcfcec64f8d0dc888466b1c99b7069d258c (patch) | |
| tree | 297f048b82c93abdd5f36c506d3290aee96df12a /spec/scope.md | |
| parent | cea204e979899113614c4f7c5dd1ba25ff61e659 (diff) | |
Scoping (not really) rules for special names
Diffstat (limited to 'spec/scope.md')
| -rw-r--r-- | spec/scope.md | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/spec/scope.md b/spec/scope.md index bf2e3cd0..b015f463 100644 --- a/spec/scope.md +++ b/spec/scope.md @@ -20,6 +20,12 @@ The definition for an identifier is chosen from the potential definitions based The definition of *program order* for identifier tokens follows the order of BQN [execution](evaluate.md). It corresponds to the order of a particular traversal of the abstract syntax tree for a program. To find the relative ordering of two identifiers in a program, we consider the highest-depth node that they both belong to; in this node they must occur in different components, or that component would be a higher-depth node containing both of them. In most nodes, the program order goes from right to left: components further to the left come earlier in program order. The exceptions are `PROGRAM`, `BODY`, `list`, `subject` (for stranding), and body case (`FCase`, `_mCase`, `_cCase_`, `FMain`, `_mMain`, `_cMain_`, `brSub`, `BrFunc`, `_brMod1`, and `_brMod2_`) nodes, in which program order goes in the opposite order, from left to right (some assignment target nodes also contain lists or strands, but their ordering is irrelevant because if two identifiers with the same name appear in such a list, then it can't be a definition). +## Special names + +Special names such as `π©` or `π£` 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. + +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. 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 `π¨`). + ## Variables A *variable* is an entity that permits two operations: it can be *set* to a particular value, and its *value* can be obtained, resulting in the last value it was set to. When either operation is performed it is referred to as *accessing* the variable. |
