diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-03-24 22:41:38 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-03-24 22:41:38 -0400 |
| commit | 46e989035fa921a5a32169cc0a9b897ec313cc2e (patch) | |
| tree | d92737c676f75ef4e752cff095b36fe20a5dfe09 /spec | |
| parent | 51ddc6a0797452b0f4ae977133038ce2439fbead (diff) | |
Specify function Undo headers
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/README.md | 2 | ||||
| -rw-r--r-- | spec/evaluate.md | 2 | ||||
| -rw-r--r-- | spec/grammar.md | 7 | ||||
| -rw-r--r-- | spec/inferred.md | 4 |
4 files changed, 13 insertions, 2 deletions
diff --git a/spec/README.md b/spec/README.md index e536b5fd..e7f86e49 100644 --- a/spec/README.md +++ b/spec/README.md @@ -2,7 +2,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](../doc/README.md) 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](../doc/README.md) 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. diff --git a/spec/evaluate.md b/spec/evaluate.md index 625192f4..1ef6486a 100644 --- a/spec/evaluate.md +++ b/spec/evaluate.md @@ -14,7 +14,7 @@ A `PROGRAM` or `BODY` is a list of `STMT`s, which are evaluated in program order 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. diff --git a/spec/grammar.md b/spec/grammar.md index af1bb52d..c79cbc71 100644 --- a/spec/grammar.md +++ b/spec/grammar.md @@ -78,9 +78,16 @@ A header looks like a name for the thing being headed, or its application to inp FuncHead = headW? ( F | "๐" ) headX | sl | "(" subExpr ")" | brSub | list # subject, | ANY ( "โฟ" ANY )+ # but not s + | 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](inferred.md#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 diff --git a/spec/inferred.md b/spec/inferred.md index 18cd67dc..bfc9dbda 100644 --- a/spec/inferred.md +++ b/spec/inferred.md @@ -162,6 +162,10 @@ Inverses of other modifiers and derived functions or modifiers obtained from the |---------|--------- | `` ` `` | `{!0<=๐ฉ โ ๐จ (ยป๐ฝโผยจโข){(โโพโ๐ฝ1โธโ)โ(1<โ )โ๐ฝ} ๐ฉ}` +### Undo headers + +An `UndoHead` header specifies how a block function acts when undone. Like ordinary headers, undo headers are searched for a match when a block function `F` is undone, or when `Fห` is undone with two arguments (including the two modifier cases `๐ฝโk` and `๐ฝ๐พk` from the previous section). An `UndoHead` without `"ห"` matches the `Fโผ` case while one with `"ห"` matches the `Fหโผ` case. The left and right arguments are matched to `headW` and `headX` as with ordinary headers, and the first matching case is evaluated to give the result of the Undo-derived function. + ## Under The Under 2-modifier `โพ` conceptually applies its left operand under the action of its right operand. Setting `zโ๐จ๐ฝโพ๐พ๐ฉ`, it satisfies `(๐จ๐ฝโ๐พ๐ฉ) โก ๐พz`. We might say that `๐พ` transforms values to a new domain, and `โพ๐พ` lifts actions `๐ฝ` performed in this domain to the original domain of values. For example, addition in the logarithmic domain corresponds to multiplication in the linear domain: `+โพ(โโผ)` is `ร` (but less precise if computed in floating point). |
