From 7ef8161ca78a0b807d13f64cdfbf8679bbc8d6fe Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 16 Nov 2021 21:36:14 -0500 Subject: Specify monadic modified assignment --- docs/spec/evaluate.html | 2 +- docs/spec/grammar.html | 2 +- spec/evaluate.md | 2 +- spec/grammar.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/spec/evaluate.html b/docs/spec/evaluate.html index 4c5c585e..b80c60ab 100644 --- a/docs/spec/evaluate.html +++ b/docs/spec/evaluate.html @@ -19,7 +19,7 @@

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 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 LHS_NAME, or an lhsList where every LHS_ENTRY is an LHS_NAME or lhs "⇐" LHS_NAME, so that it can be considered a list of LHS_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 LHS_NAME node used to get it from v.

-

Modified assignment is the subject assignment rule lhs Derv "↩" subExpr. In this case, lhs should be evaluated as if it were a subExpr (the syntax is a subset of subExpr), and the result of the function application lhs Derv subExpr should be assigned to lhs, and is also the result of the modified assignment expression.

+

Modified assignment is the subject assignment rule lhs Derv "↩" subExpr?. In this case, lhs is evaluated as if it were a subExpr (the syntax is a subset of subExpr), and passed as an argument to Derv. The full application is lhs Derv subExpr, if subExpr is given, and Derv lhs otherwise. Its value is assigned to lhs, and is also the result of the modified assignment expression.

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 and built-ins). 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 braced construct such as BraceFunc is defined by the evaluation of the statements it contains after all parameters are accepted. 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.

A Return node creates a return function. As discussed in the scoping rules, its identifier indicates a namespace from a particular block evaluation. When called, the function causes an error if that block has finished execution, or if the call includes a left argument 𝕨. Otherwise, evaluation stops immediately, and resumes at the end of the block where it returns the right argument 𝕩 from that block.

diff --git a/docs/spec/grammar.html b/docs/spec/grammar.html index da83d87c..457fd039 100644 --- a/docs/spec/grammar.html +++ b/docs/spec/grammar.html @@ -63,7 +63,7 @@ lhs = s | lhsList | lhsStr subExpr = arg | lhs ASGN subExpr - | lhs Derv "↩" subExpr # Modified assignment + | lhs Derv "↩" subExpr? # Modified assignment

A header looks like a name for the thing being headed, or its application to inputs (possibly twice in the case of modifiers). As with assignment, it is restricted to a simple form with no extra parentheses. The full list syntax is allowed for arguments. As a special rule, a monadic function header specifically can omit the function when the argument is not just a name (as this would conflict with a subject label). The following cases define only headers with arguments, which are assumed to be special cases; there can be any number of these. Headers without arguments can only refer to the general case—note that operands are not pattern matched—so there can be at most two of these kinds of headers, indicating the monadic and dyadic cases.

headW    = subject | "𝕨"
diff --git a/spec/evaluate.md b/spec/evaluate.md
index 7ddbb616..a508a895 100644
--- a/spec/evaluate.md
+++ b/spec/evaluate.md
@@ -30,7 +30,7 @@ An *assignment* is one of the four rules containing `ASGN`. It is evaluated by f
 
 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 `LHS_NAME`, or an `lhsList` where every `LHS_ENTRY` is an `LHS_NAME` or `lhs "⇐" LHS_NAME`, so that it can be considered a list of `LHS_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 `LHS_NAME` node used to get it from `v`.
 
-*Modified assignment* is the subject assignment rule `lhs Derv "↩" subExpr`. In this case, `lhs` should be evaluated as if it were a `subExpr` (the syntax is a subset of `subExpr`), and the result of the function application `lhs Derv subExpr` should be assigned to `lhs`, and is also the result of the modified assignment expression.
+*Modified assignment* is the subject assignment rule `lhs Derv "↩" subExpr?`. In this case, `lhs` is evaluated as if it were a `subExpr` (the syntax is a subset of `subExpr`), and passed as an argument to `Derv`. The full application is `lhs Derv subExpr`, if `subExpr` is given, and `Derv lhs` otherwise. Its value is assigned to `lhs`, and is also the result of the modified assignment expression.
 
 ### Expressions
 
diff --git a/spec/grammar.md b/spec/grammar.md
index 64c607bf..92d26c1a 100644
--- a/spec/grammar.md
+++ b/spec/grammar.md
@@ -67,7 +67,7 @@ Subject expressions are complicated by the possibility of list and namespace ass
     lhs      = s | lhsList | lhsStr
     subExpr  = arg
              | lhs ASGN subExpr
-             | lhs Derv "↩" subExpr       # Modified assignment
+             | lhs Derv "↩" subExpr?      # Modified assignment
 
 A header looks like a name for the thing being headed, or its application to inputs (possibly twice in the case of modifiers). As with assignment, it is restricted to a simple form with no extra parentheses. The full list syntax is allowed for arguments. As a special rule, a monadic function header specifically can omit the function when the argument is not just a name (as this would conflict with a subject label). The following cases define only headers with arguments, which are assumed to be special cases; there can be any number of these. Headers without arguments can only refer to the general case—note that operands are not pattern matched—so there can be at most two of these kinds of headers, indicating the monadic and dyadic cases.
 
-- 
cgit v1.2.3