diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/README.md | 2 | ||||
| -rw-r--r-- | spec/inferred.md | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/spec/README.md b/spec/README.md index bc826a76..8d09ab2e 100644 --- a/spec/README.md +++ b/spec/README.md @@ -4,7 +4,7 @@ This directory gives a specification for BQN. 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 core ideas of BQN functionality and how it might be used. -All normative sections of the core BQN specification (that is, excluding system-provided values) are complete except for the behavior of fill elements. The non-normative commentary on primitive definitions is also not yet complete. +All normative sections of the core BQN specification (that is, excluding system-provided values) are now complete, but the non-normative commentary on primitive definitions is still missing a few sections. The BQN specification consists of the following documents: - [Types](types.md) diff --git a/spec/inferred.md b/spec/inferred.md index 3264df06..ae2ccd05 100644 --- a/spec/inferred.md +++ b/spec/inferred.md @@ -30,6 +30,32 @@ Identity values for the arithmetic primitives below must be recognized. Under Fo Additionally, the identity of `βΎΛ` must be recognized: if `0=β π©` and `1<=π©`, then `βΎΛπ©` is `(0βΎ2ββ’π©)β₯π©`. If `1==π©`, then there is no identity element, as the result of `βΎ` always has rank at least 1, but the cell rank is 0. +## Fill elements + +Any BQN array can have a *fill element*, which is a sort of "default" value for the array. The reference implementations use `Fill` to access this element, and it is used primarily for Take (`β`), First (`β`), and Nudge (`Β«`, `Β»`). One way to extract the fill element of an array `a` in BQN is `β0β₯a`. + +A fill element can be either `0`, `' '`, or an array of valid fill elements. If the fill element is an array, then it may also have a fill element (since it is an ordinary BQN array). The fill element is meant to describe the shared structure of the elements of an array: for example, the fill element of an array of numbers should be `0`, while the fill element for an array of variable-length lists should probably be `β¨β©`. However, the fill element, unlike other inferred properties, does not satisfy any particular constraints that relate it to its array. + +### Required functions + +Combinators `β£β’!ΛΛΒ΄ΛβββΈβββΆβ` do not affect fill element computation: if the combinator calls a function that computes a fill element, then that fill element must be retained if the result is passed to other functions or returned. `β` constructs arrays if its right operand is or contains arrays, and the fill elements of these arrays are not specified; converting `π©` to a fill element is a reasonable choice in some cases but not others. + +Arithmetic primitivesβall valences of `+-ΓΓ·ββββ|Β¬β§β¨` and dyadic `<>β =β€β₯`βobtain their fill elements by applying to the fill elements of the arguments. If this is an error, there is no fill element; otherwise, the fill element is the result, with all numbers in it changed to `0` and all characters changed to `' '`. + +Fill elements for many primitives are given in the table below. The "Fill" column indicates the strategy used to compute the result's fill. Fields `0`, `0βπ©`, and `0β0π©` indicate the fill directly, while `β’` and `β©` indicate that the fill is to be computed from the argument fills (if not all arguments have fills, then the fill element is unspecified). For `β’`, the fill element of the result is the fill element of `π©`. For `β©`, the fill is equal to the fill values for multiple arrays, provided that they are all equal (it's unspecified if they are not all equal). In the two argument case, these arrays are `π¨` and `π©`. In the one-argument case, they are the elements of `π©`; however, if `π©` is empty, then the result's fill is the fill of the fill of `π©`. + +| Fill | Monads | Dyads | Modifiers +|--------|------------|-------------|---------- +| `β’` | `β₯β½ββββ§β¨` | `β₯β½βββββ/β·` | `` π½` `` +| `0` | `β’/ββββ·ββ` | `βββββ` +| `β©` | `>βΎ` | `βΎβ` +| `0βπ©` | `ββ` +| `0β0π©` | `β` + +For Group and Group Indices (`β`), the fill element of the result and its elements are both specified: the fill element of each element of the result is the same as that of `π©` for Group, and is `0` for Group Indices. The fill element of the result is `(0β1π¨)βπ©` for Group, and `β₯β<0β1π©` for Group Indices. + +Fill elements of iteration modifiers such as `Β¨β` are not specified. It is reasonable to define the fill element of `π½β` or `π½Β¨` to be `π½` applied to the fill elements of the arguments. Regardless of definition, computing the fill element cannot cause side effects or an error. + ## Undo The Undo 1-modifier `βΌ`, given an operand `π½` and argument `π©`, and possibly a left argument `π¨`, finds a value `y` such that `π©β‘π¨π½y`, that is, an element of the pre-image of `π©` under `π½` or `π¨π½β’`. Thus it satisfies the constraint `π© β‘ π¨π½π¨π½βΌπ©` (`π¨π½βΌβ’` is a *right inverse* of `π¨π½β’`) provided `π½βΌ` and `π½` both complete without error. `π½βΌ` should of course give an error if no inverse element exists, and can also fail if no inverse can be found. It is also preferred for `π½βΌ` to give an error if there are many choices of inverse with no clear way to choose one of them: for example, `0βΏ0βm` returns the diagonal of matrix `m`; `0βΏ0ββΌ2βΏ3` requires values to be chosen for the off-diagonal elements in its result. It is better to give an error, encouraging the programmer to use a fully-specified approach like `2βΏ3βΎ(0βΏ0βΈβ)` applied to a matrix of initial elements, than to return a result that could be very different from other implementations. |
