diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-06-13 14:02:54 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-06-13 14:02:54 -0400 |
| commit | 316ae01c16db690a972fcba9ce735818a31773ac (patch) | |
| tree | 34edbf515e8da9a7df803dbcaa96e1831defe0f1 /spec/evaluate.md | |
| parent | 0d6c26b9aa607ff14e14e6488bace207e324022a (diff) | |
Specify []; spec is now a version 1.0 draft
Diffstat (limited to 'spec/evaluate.md')
| -rw-r--r-- | spec/evaluate.md | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/spec/evaluate.md b/spec/evaluate.md index 48d00014..de3aca44 100644 --- a/spec/evaluate.md +++ b/spec/evaluate.md @@ -28,9 +28,11 @@ If there is no left argument, but the `BODY` contains `๐จ` or `๐` at the to ### Assignment -An *assignment* is one of the four rules containing `ASGN`. It is evaluated by first evaluating the right-hand-side `subExpr`, `FuncExpr`, `_m1Expr`, or `_m2Exp_` 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, *destructuring assignment* is performed when an `lhs` is `lhsList` or `lhsStr`. 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 `"ยท"` is also possible in place of a `NAME`, and performs no assignment. +An *assignment* is one of the four rules containing `ASGN`. It is evaluated by first evaluating the right-hand-side `subExpr`, `FuncExpr`, `_m1Expr`, or `_m2Exp_` 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, *destructuring assignment* is performed when an `lhs` is `lhsList`, `lhsStr`, or `lhsArray`. 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 `"ยท"` is also possible in place of a `NAME`, and performs no assignment. -The right-hand-side value, here called `v`, in destructuring assignment must be a list (rank 1 array) or namespace. If it's a list, then each `LHS_ENTRY` node must be an `LHS_ELT`. The left-hand side is treated as a list of `lhs` targets, and matched to `v` element-wise, with an error if the two lists differ in length. If `v` is a namespace, then the left-hand side must be an `lhsStr` where every `LHS_ATOM` is an `NAME`, or an `lhsList` where every `LHS_ENTRY` is an `NAME` or `lhs "โ" NAME`, so that it can be considered a list of `NAME` nodes some of which are also associated with `lhs` nodes. To perform the assignment, the value of each name is obtained from the namespace `v`, giving an error if `v` does not define that name. The value is assigned to the `lhs` node if present (which may be a destructuring assignment or simple subject assignment), and otherwise assigned to the same `NAME` node used to get it from `v`. +In assignment to `lhsList` or `lhsStr`, the right-hand-side value, here called `v`, must be a list (rank 1 array) or namespace. If it's a list, then each `LHS_ENTRY` node must be an `LHS_ELT`. The left-hand side is treated as a list of `lhs` targets, and matched to `v` element-wise, with an error if the two lists differ in length. If `v` is a namespace, then the left-hand side must be an `lhsStr` where every `LHS_ATOM` is an `NAME`, or an `lhsList` where every `LHS_ENTRY` is an `NAME` or `lhs "โ" NAME`, so that it can be considered a list of `NAME` nodes some of which are also associated with `lhs` nodes. To perform the assignment, the value of each name is obtained from the namespace `v`, giving an error if `v` does not define that name. The value is assigned to the `lhs` node if present (which may be a destructuring assignment or simple subject assignment), and otherwise assigned to the same `NAME` node used to get it from `v`. + +Assignment to `lhsArray` destructures the major cells of right-hand-side value `v`, which must be an array of rank at least 1. The number of cells in `v` is its length `l`, that is, the first element of its shape. The shape of each is the shape of `v` without its first element, and the cell ravels are formed by splitting `v`'s ravel evenly into `l` sections. Besides this difference in how `v` is divided, assignment behaves the same way as assignment of a list `v` to `lhsList`. 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 `โฉ` encounters an error but it's caught with `โ`, some of the assignment may have already been performed, changing variable values. @@ -38,7 +40,9 @@ A destructuring assignment is performed in program order, or equivalently index ### Expressions -We now give rules for evaluating an `atom`, `Func`, `_mod1` or `_mod2_` expression (the possible options for `ANY`). A literal or primitive `sl`, `Fl`, `_ml`, or `_cl_` has a fixed value defined by the specification ([literals](literal.md) and [built-ins](primitive.md)). An identifier `s`, `F`, `_m`, or `_c_`, if not preceded by `atom "."`, 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 `atom "."`, then the `atom` 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 `"(" _modExpr ")"` simply returns the result of the interior expression. A block is defined by the evaluation of the statements it contains after all parameters are accepted, as described above. Finally, a list `"โจ" โ? ( ( EXPR โ )* EXPR โ? )? "โฉ"` or `ANY ( "โฟ" ANY )+` 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. +We now give rules for evaluating an `atom`, `Func`, `_mod1` or `_mod2_` expression (the possible options for `ANY`). A literal or primitive `sl`, `Fl`, `_ml`, or `_cl_` has a fixed value defined by the specification ([literals](literal.md) and [built-ins](primitive.md)). An identifier `s`, `F`, `_m`, or `_c_`, if not preceded by `atom "."`, 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 `atom "."`, then the `atom` 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 `"(" _modExpr ")"` simply returns the result of the interior expression. A block is defined by the evaluation of the statements it contains after all parameters are accepted, as described above. + +A list `"โจ" โ? ( ( EXPR โ )* EXPR โ? )? "โฉ"` or `ANY ( "โฟ" ANY )+` 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. The square bracket notation `"[" โ? ( EXPR โ )* EXPR โ? "]"` evaluates expressions in the same way, but makes them into major cells of an array instead of elements. The result is identical to applying the [primitive](primitive.md) function Merge (`>`) to a list of the expression results. Rules in the table below are function and modifier evaluation. | L | Left | Called | Right | R | Types |
