diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-04-16 17:23:57 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-04-16 17:23:57 -0400 |
| commit | 7de47f9a7db71a179ba3124d39cc2c5be2000fd4 (patch) | |
| tree | 6441aa12e97b011476f3aab36efc2c479adc9e13 /docs | |
| parent | 987e6890f78e54402b1355201d45e2fbce1fd992 (diff) | |
Specify ordering of destructuring ↩ with error catching
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/spec/evaluate.html | 1 | ||||
| -rw-r--r-- | docs/spec/scope.html | 2 |
2 files changed, 2 insertions, 1 deletions
diff --git a/docs/spec/evaluate.html b/docs/spec/evaluate.html index c9c45110..9f00a28d 100644 --- a/docs/spec/evaluate.html +++ b/docs/spec/evaluate.html @@ -20,6 +20,7 @@ <h3 id="assignment"><a class="header" href="#assignment">Assignment</a></h3> <p>An <em>assignment</em> is one of the four rules containing <code><span class='Function'>ASGN</span></code>. It is evaluated by first evaluating the right-hand-side <code><span class='Value'>subExpr</span></code>, <code><span class='Function'>FuncExpr</span></code>, <code><span class='Modifier'>_m1Expr</span></code>, or <code><span class='Modifier2'>_m2Exp_</span></code> expression, and then storing the result in the left-hand-side identifier or identifiers. The result of the assignment expression is the result of its right-hand side. Except for subjects, only a lone identifier is allowed on the left-hand side and storage sets it equal to the result. For subjects, <em>destructuring assignment</em> is performed when an <code><span class='Value'>lhs</span></code> is <code><span class='Value'>lhsList</span></code> or <code><span class='Value'>lhsStr</span></code>. Destructuring assignment is performed recursively by assigning right-hand-side values to the left-hand-side targets, with single-identifier assignment as the base case. The target <code><span class='String'>"·"</span></code> is also possible in place of a <code><span class='Function'>NAME</span></code>, and performs no assignment.</p> <p>The right-hand-side value, here called <code><span class='Value'>v</span></code>, in destructuring assignment must be a list (rank 1 array) or namespace. If it's a list, then each <code><span class='Function'>LHS_ENTRY</span></code> node must be an <code><span class='Function'>LHS_ELT</span></code>. The left-hand side is treated as a list of <code><span class='Value'>lhs</span></code> targets, and matched to <code><span class='Value'>v</span></code> element-wise, with an error if the two lists differ in length. If <code><span class='Value'>v</span></code> is a namespace, then the left-hand side must be an <code><span class='Value'>lhsStr</span></code> where every <code><span class='Function'>LHS_ATOM</span></code> is an <code><span class='Function'>NAME</span></code>, or an <code><span class='Value'>lhsList</span></code> where every <code><span class='Function'>LHS_ENTRY</span></code> is an <code><span class='Function'>NAME</span></code> or <code><span class='Value'>lhs</span> <span class='String'>"⇐"</span> <span class='Function'>NAME</span></code>, so that it can be considered a list of <code><span class='Function'>NAME</span></code> nodes some of which are also associated with <code><span class='Value'>lhs</span></code> nodes. To perform the assignment, the value of each name is obtained from the namespace <code><span class='Value'>v</span></code>, giving an error if <code><span class='Value'>v</span></code> does not define that name. The value is assigned to the <code><span class='Value'>lhs</span></code> node if present (which may be a destructuring assignment or simple subject assignment), and otherwise assigned to the same <code><span class='Function'>NAME</span></code> node used to get it from <code><span class='Value'>v</span></code>.</p> +<p>A destructuring assignment is performed in program order, or equivalently index order, with each sub-assignment fully completed before beginning the next (a depth-first order). Thus if an assignment with <code><span class='Gets'>↩</span></code> encounters an error but it's caught with <code><span class='Modifier2'>⎊</span></code>, some of the assignment may have already been performed, changing variable values.</p> <p><em>Modified assignment</em> is the subject assignment rule <code><span class='Value'>lhs</span> <span class='Function'>Derv</span> <span class='String'>"↩"</span> <span class='Value'>subExpr</span><span class='Head'>?</span></code>. In this case, <code><span class='Value'>lhs</span></code> is evaluated as if it were a <code><span class='Value'>subExpr</span></code> (the syntax is a subset of <code><span class='Value'>subExpr</span></code>), and passed as an argument to <code><span class='Function'>Derv</span></code>. The full application is <code><span class='Value'>lhs</span> <span class='Function'>Derv</span> <span class='Value'>subExpr</span></code>, if <code><span class='Value'>subExpr</span></code> is given, and <code><span class='Function'>Derv</span> <span class='Value'>lhs</span></code> otherwise. Its value is assigned to <code><span class='Value'>lhs</span></code>, and is also the result of the modified assignment expression.</p> <h3 id="expressions"><a class="header" href="#expressions">Expressions</a></h3> <p>We now give rules for evaluating an <code><span class='Value'>atom</span></code>, <code><span class='Function'>Func</span></code>, <code><span class='Modifier'>_mod1</span></code> or <code><span class='Modifier2'>_mod2_</span></code> expression (the possible options for <code><span class='Function'>ANY</span></code>). A literal or primitive <code><span class='Value'>sl</span></code>, <code><span class='Function'>Fl</span></code>, <code><span class='Modifier'>_ml</span></code>, or <code><span class='Modifier2'>_cl_</span></code> has a fixed value defined by the specification (<a href="literal.html">literals</a> and <a href="primitive.html">built-ins</a>). An identifier <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>, if not preceded by <code><span class='Value'>atom</span> <span class='String'>"."</span></code>, must have an associated variable due to the scoping rules, and returns this variable's value, or causes an error if it has not yet been set. If it is preceded by <code><span class='Value'>atom</span> <span class='String'>"."</span></code>, then the <code><span class='Value'>atom</span></code> node is evaluated first; its value must be a namespace, and the result is the value of the identifier's name in the namespace, or an error if the name is undefined. A parenthesized expression such as <code><span class='String'>"("</span> <span class='Modifier'>_modExpr</span> <span class='String'>")"</span></code> simply returns the result of the interior expression. A braced construct such as <code><span class='Function'>BraceFunc</span></code> is defined by the evaluation of the statements it contains after all parameters are accepted. Finally, a list <code><span class='String'>"⟨"</span> <span class='Separator'>⋄</span><span class='Head'>?</span> <span class='Paren'>(</span> <span class='Paren'>(</span> <span class='Function'>EXPR</span> <span class='Separator'>⋄</span> <span class='Paren'>)</span><span class='Value'>*</span> <span class='Function'>EXPR</span> <span class='Separator'>⋄</span><span class='Head'>?</span> <span class='Paren'>)</span><span class='Head'>?</span> <span class='String'>"⟩"</span></code> or <code><span class='Function'>ANY</span> <span class='Paren'>(</span> <span class='String'>"‿"</span> <span class='Function'>ANY</span> <span class='Paren'>)</span><span class='Function'>+</span></code> consists grammatically of a list of expressions. To evaluate it, each expression is evaluated in source order and their results are placed as elements of a rank-1 array. The two forms have identical semantics but different punctuation.</p> diff --git a/docs/spec/scope.html b/docs/spec/scope.html index f5e3e2c8..ef92f370 100644 --- a/docs/spec/scope.html +++ b/docs/spec/scope.html @@ -17,7 +17,7 @@ <li>The two identifiers are the same instance (a defined variable is its own definition).</li> </ul> <p>The definition for an identifier is chosen from the potential definitions based on their containing scopes: it is the one whose containing scope does not contain or match the containing scope of any other potential definition. If for any identifier there is no definition, then the program is not valid and results in an error. This can occur if the identifier has no potential definition, and also if two potential definitions appear in the same scope. In fact, under this scheme it is never valid to make two definitions with the same name at the top level of a single scope, because both definitions would be potential definitions for the one that comes second in program order. Both definitions have the same containing scope, and any potential definition must contain or match this scope, so no potential definition can be selected.</p> -<p>The definition of <em>program order</em> for identifier tokens follows the order of BQN <a href="evaluate.html">execution</a>. 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 right come earlier in program order. The exceptions are <code><span class='Function'>PROGRAM</span></code>, <code><span class='Function'>BODY</span></code>, <code><span class='Value'>list</span></code>, <code><span class='Value'>subject</span></code> (for stranding), and body structure (<code><span class='Function'>I_CASE</span></code>, <code><span class='Function'>A_CASE</span></code>, <code><span class='Function'>IMM_BLK</span></code>, <code><span class='Function'>ARG_BLK</span></code>, and <code><span class='Value'>blSub</span></code>) 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).</p> +<p>The definition of <em>program order</em> for identifier tokens follows the order of BQN <a href="evaluate.html">execution</a>. 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 right come earlier in program order. The exceptions are <code><span class='Function'>PROGRAM</span></code>, <code><span class='Function'>BODY</span></code>, <code><span class='Value'>list</span></code>, <code><span class='Value'>subject</span></code> (for stranding), <code><span class='Value'>lhsList</span></code>, <code><span class='Value'>lhsStr</span></code>, and body structure (<code><span class='Function'>I_CASE</span></code>, <code><span class='Function'>A_CASE</span></code>, <code><span class='Function'>IMM_BLK</span></code>, <code><span class='Function'>ARG_BLK</span></code>, and <code><span class='Value'>blSub</span></code>) nodes, in which program order goes in the opposite order, from left to right.</p> <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> |
