From ab74b5cee5260544dd651b7edc22ad8b3554cdde Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 19 Jun 2021 22:00:51 -0400 Subject: =?UTF-8?q?Clarify=20valid=20uses=20of=20=F0=9D=95=8E=20as=20Nothi?= =?UTF-8?q?ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/spec/evaluate.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/spec/evaluate.html') diff --git a/docs/spec/evaluate.html b/docs/spec/evaluate.html index 6fdf0a0f..2d28eb12 100644 --- a/docs/spec/evaluate.html +++ b/docs/spec/evaluate.html @@ -14,7 +14,7 @@

A block consists of several BODY terms, some of which may have an accompanying header describing accepted inputs and how they are processed. An immediate block brImm can only have one BODY, and is evaluated by evaluating the code in it. Other types of blocks do not evaluate any BODY immediately, but instead return a function or modifier that obtains its result by evaluating a particular BODY. The BODY is identified and evaluated once the block has received enough inputs (operands or arguments), which for modifiers can take one or two calls: if two calls are required, then on the first call the operands are simply stored and no code is evaluated yet. Two calls are required if there is more than one BODY term, if the BODY contains the special names 𝕨𝕩𝕤𝕎𝕏𝕊, or if its header specifies arguments (the header-body combination is a _mCase or _cCase_). Otherwise only one is required.

To evaluate a block when enough inputs have been received, first the correct case must be identified. To do this, first each special case (FCase, _mCase, or _cCase_), excluding FCase nodes containing UndoHead, is checked in order to see if its arguments are strucurally compatible with the given arguments. That is, is headW is a subject, there must be a left argument matching that structure, and if headX is a subject, the right argument must match that structure. This means that 𝕨 not only matches any left argument but also no argument. The test for compatibility is the same as for multiple assignment described below, except that the header may contain constants, which must match the corresponding part of the given argument. If no special case matches, then an appropriate general case (FMain, _mMain, or _cMain_) is used: if there are two, the first is used with no left argument and the second with a left argument; if there are one, it is always used, and if there are none, an error results.

The only remaining step before evaluating the BODY is to bind the inputs and other names. Special names are always bound when applicable: 𝕨𝕩𝕤 if arguments are used, 𝕨 if there is a left argument, 𝕗𝕘 if operands are used, and _𝕣 and _𝕣_ for modifiers and combinators, respectively. Any names in the header are also bound, allowing multiple assignment for arguments.

-

If there is no left argument, but the BODY contains 𝕨 at the top level, then it is conceptually re-parsed with 𝕨 replaced by · to give a monadic version before application; this modifies the syntax tree by replacing some instances of arg with nothing. However, it also causes an error if, in a function that is called with no left argument, 𝕨 is used as an operand or list element, where nothing is not allowed by the grammar. The same effect can also be achieved dynamically by treating · as a value and checking for it during execution. If it is used as a left argument, then the function should instead be called with no left argument (and similarly in trains); it it is used as a right argument, then the function and its left argument are evaluated but rather than calling the function · is "returned" immediately; and if it is used in another context then it causes an error.

+

If there is no left argument, but the BODY contains 𝕨 or 𝕎 at the top level, then it is conceptually re-parsed with 𝕨 replaced by · to give a monadic version before application; this modifies the syntax tree by replacing some instances of arg with nothing. However, it also causes an error if, in a function that is called with no left argument, 𝕨 is used as an operand or list element, where nothing is not allowed by the grammar. In the case of 𝕎 it's almost always an error, only valid if used alone in a statement or as the left part of a Fork. True re-parsing is not required as the same effect can also be achieved dynamically by treating · as a value and checking for it during execution. If it's used as a left argument, then the function should instead be called with no left argument (and similarly in trains); if it's used as a right argument, then the function and its left argument are evaluated but rather than calling the function · is "returned" immediately; and if it's used in another context then it causes an error.

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.

-- cgit v1.2.3