From 46e989035fa921a5a32169cc0a9b897ec313cc2e Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 24 Mar 2021 22:41:38 -0400 Subject: Specify function Undo headers --- docs/spec/evaluate.html | 2 +- docs/spec/grammar.html | 8 +++++++- docs/spec/index.html | 2 +- docs/spec/inferred.html | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) (limited to 'docs') diff --git a/docs/spec/evaluate.html b/docs/spec/evaluate.html index d1ab7b80..892aa7a5 100644 --- a/docs/spec/evaluate.html +++ b/docs/spec/evaluate.html @@ -11,7 +11,7 @@

The result of parsing a valid BQN program is a PROGRAM, and the program is run by evaluating this term.

A PROGRAM or BODY is a list of STMTs, which are evaluated in program order. A result is always required for BODY nodes, and sometimes for PROGRAM nodes (for example, when loaded with โ€ขImport). If any identifiers in the node's scope are exported, or any of its statements is an EXPORT, then the result is the namespace created in order to evaluate the node. If a result is required but the namespace case doesn't apply, then the last STMT node must be an EXPR and its result is used. The statement EXPR evaluates some APL code and possibly assigns the results, while nothing evaluates any subject or Derv terms it contains but discards the results. An EXPORT statement performs no action.

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_) 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.

+

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.

Assignment

diff --git a/docs/spec/grammar.html b/docs/spec/grammar.html index dca88643..46509c05 100644 --- a/docs/spec/grammar.html +++ b/docs/spec/grammar.html @@ -73,9 +73,15 @@ FuncHead = headW? ( F | "๐•Š" ) headX | sl | "(" subExpr ")" | brSub | list # subject, | ANY ( "โ€ฟ" ANY )+ # but not s -_m1Head = headW? Mod1H1 headX + | UndoHead +_m1Head = headW? Mod1H1 headX _m2Head_ = headW? Mod2H1 headX +

Additionally, an inference header doesn't affect evaluation of the function, but describes how an inferred property (Undo) should be computed. Here "หœ" and "โผ" are both specific instances of the _ml token.

+
UndoHead = headW? ( F | "๐•Š" )      "โผ" headX
+         | headW  ( F | "๐•Š" ) "หœ"  "โผ" headX
+         |        ( F | "๐•Š" ) "หœ"? "โผ"
+

A braced block contains bodies, which are lists of statements, separated by semicolons and possibly preceded by headers, which are separated from the body with a colon. Multiple bodies allow different handling for various cases, which are pattern-matched by headers. For an immediate block there are no inputs, so there can only be one possible case and one body. Functions and modifiers allow any number of "matched" bodies, with headers that have arguments, followed by at most two "main" bodies with either no headers or headers without arguments. If there is one main body, it is ambivalent, but two main bodies refer to the monadic and dyadic cases.

BODY     = PROGRAM
 FCase    = โ‹„? FuncHead ":" BODY
diff --git a/docs/spec/index.html b/docs/spec/index.html
index 5c2017e1..4f7d4faa 100644
--- a/docs/spec/index.html
+++ b/docs/spec/index.html
@@ -5,7 +5,7 @@
 
 
 

BQN specification

-

This document, and the others in this directory (linked in the list below) make up the pre-versioning BQN specification. The specification differs from the documentation in that its purpose is only to describe the exact details of BQN's operation in the most quickly accessible way, rather than to explain the central ideas of BQN functionality and how it might be used. The core of BQN, which excludes system-provided values, is now almost completely specified. Three planned featuresโ€”syntax for system-provided values, inferred property function headers, and an extension to allow low-rank elements in the argument to Joinโ€”have not yet been added, and the spec will continue to be edited further to improve clarity and cover any edge cases that have been missed.

+

This document, and the others in this directory (linked in the list below) make up the pre-versioning BQN specification. The specification differs from the documentation in that its purpose is only to describe the exact details of BQN's operation in the most quickly accessible way, rather than to explain the central ideas of BQN functionality and how it might be used. The core of BQN, which excludes system-provided values, is now almost completely specified. Two planned featuresโ€”syntax for system-provided values and an extension to allow low-rank elements in the argument to Joinโ€”have not yet been added, and the spec will continue to be edited further to improve clarity and cover any edge cases that have been missed.

Under this specification, a language implementation is a BQN pre-version implementation if it behaves as specified for all input programs. It is a BQN pre-version implementation with extensions if it behaves as specified in all cases where the specification does not require an error, but behaves differently in at least one case where it requires an error. It is a partial version of either of these if it doesn't conform to the description but differs from a conforming implementation only by rejecting with an error some programs that the conforming implementation accepts. As the specification is not yet versioned, other instances of the specification define these terms in different ways. An implementation can use one of these term if it conforms to any instance of the pre-versioning BQN specifications that defines them. When versioning is begun, there will be only one specification for each version.

The following documents are included in the BQN specification. A BQN program is a sequence of Unicode code points: to evaluate it, it is converted into a sequence of tokens using the token formation rules, then these tokens are arranged in a syntax tree according to the grammar, and then this tree is evaluated according to the evaluation semantics. The program may be evaluated in the presence of additional context such as a filesystem or command-line arguments; this context is presented to the program and manipulated through the system-provided values.