diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-08-07 20:57:51 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-08-07 20:57:51 -0400 |
| commit | c7ef3aabb54791b597d4095011ff048c2a13f6ac (patch) | |
| tree | 45967d042b204df64097a57cf6c72c4b4be8d1f6 /doc | |
| parent | 7bf2aa4054b8378a76dff63acdccbcdad91f68e6 (diff) | |
Document use of fill elements for merge of empty
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/couple.md | 2 | ||||
| -rw-r--r-- | doc/fill.md | 4 | ||||
| -rw-r--r-- | doc/types.md | 2 |
3 files changed, 5 insertions, 3 deletions
diff --git a/doc/couple.md b/doc/couple.md index 4603b22b..95806d8f 100644 --- a/doc/couple.md +++ b/doc/couple.md @@ -30,7 +30,7 @@ In all cases what these functions do is more like reinterpreting existing data t ⥊ ⥊¨ a ∾ ⥊ ⥊¨ a -The way this happens, and the constraint that all inner arrays have the same shape, is closely connected to the concept of an array, and like [Table](map.md#table) `⌜`, Merge might be considered a fundamental way to build up multidimensional arrays from lists. In both cases rank-0 or [unit](enclose.md#whats-a-unit) arrays are somewhat special. They are the [identity value](fold.md#identity-values) of a function with Table, and can be produced by Merge [inverse](undo.md), `>⁼` **on a list**, which forces either the outer or inner shape to be empty (BQN chooses `>⁼` to be `<`, but only on an array, as `>` cannot produce non-arrays). Merge has another catch as well: it cannot produce arrays with a `0` in the shape, except at the end, unless fills can be specified. +The way this happens, and the constraint that all inner arrays have the same shape, is closely connected to the concept of an array, and like [Table](map.md#table) `⌜`, Merge might be considered a fundamental way to build up multidimensional arrays from lists. In both cases rank-0 or [unit](enclose.md#whats-a-unit) arrays are somewhat special. They are the [identity value](fold.md#identity-values) of a function with Table, and can be produced by Merge [inverse](undo.md), `>⁼` **on a list**, which forces either the outer or inner shape to be empty (BQN chooses `>⁼` to be `<`, but only on an array, as `>` cannot produce non-arrays). Merge has another catch as well: it cannot produce arrays with a `0` in the shape, except at the end, without relying on a [fill](fill.md) element. ⊢ e ← ⟨⟩¨ ↕3 ≢ > e diff --git a/doc/fill.md b/doc/fill.md index ed93b02c..6b4bd53c 100644 --- a/doc/fill.md +++ b/doc/fill.md @@ -4,7 +4,7 @@ A few array operations need an array element to use when no existing element applies. BQN tries to maintain a "default" element for every array, known as a fill element, for this purpose. If it's known, the fill element is a nested array structure where each atom is either `0` or `' '`. If no fill is known, a function that requests it results in an error. -Fills are used by [Take](take.md) (`↑`) when a value in `𝕨` is larger than the corresponding length in `𝕩`, by the two [Nudge](shift.md) functions (`»«`) when `𝕩` is non-empty, and by [Reshape](reshape.md) (`⥊`) when `𝕨` contains `↑`. Except for these specific cases, the fill value an array has can't affect the program. The result of [Match](match.md) (`≡`) doesn't depend on fills, and any attempt to compute a fill can't cause side effects. +Fills are used by [Take](take.md) (`↑`) when a value in `𝕨` is larger than the corresponding length in `𝕩`, by the two [Nudge](shift.md) functions (`»«`) when `𝕩` is non-empty, by [Merge](couple.md) (`>`) when `𝕩` is empty, and by [Reshape](reshape.md) (`⥊`) when `𝕨` contains `↑`. Except for these specific cases, the fill value an array has can't affect the program. The result of [Match](match.md) (`≡`) doesn't depend on fills, and any attempt to compute a fill can't cause side effects. ## Using fills @@ -24,6 +24,8 @@ Nudge Left or Right shifts the array over and places a fill in the vacated space »⟨⟩ # Fill not needed +If the argument to [Merge](couple.md) is empty then its result will be as well, since the shape `≢𝕩` is a prefix of `≢>𝕩`. However, the remainder of the result shape is determined by the elements of `𝕩`, so if there are none then Merge uses the fill element to decide what the result shape should be. + [Reshape](reshape.md#computed-lengths) (`⥊`) uses the fill when `𝕨` contains `↑` and the product of the rest of `𝕨` doesn't evenly divide the number of elements in `𝕩`. ↑‿8 ⥊ "completepart" diff --git a/doc/types.md b/doc/types.md index f3b7f414..96870844 100644 --- a/doc/types.md +++ b/doc/types.md @@ -71,7 +71,7 @@ Other linear combinations such as adding two characters or negating a character A BQN array is a multidimensional arrangement of data. This means it has a certain [*shape*](shape.md), which is a finite list of natural numbers giving the length along each axis, and it contains an *element* for each possible [*index*](indices.md), which is a choice of one natural number that's less than each axis length in the shape. The total number of elements, or *bound*, is then the product of all the lengths in the shape. The shape may have any length including zero, and this shape is known as the array's *rank*. An array of rank 0, which always contains exactly one element, is called a *unit*, while an array of rank 1 is called a *list* and an array of rank 2 is called a *table*. -Each array—empty or nonempty—has an inferred property called a [*fill*](fill.md). The fill either indicates what element should be used to pad an array, or that such an element is not known and an error should result. Fills can be used by [Take](take.md) (`↑`), the two [Nudge](shift.md) functions (`»«`), and [Reshape](reshape.md) (`⥊`). +Each array—empty or nonempty—has an inferred property called a [*fill*](fill.md). The fill either indicates what element should be used to pad an array, or that such an element is not known and an error should result. Fills can be used by [Take](take.md) (`↑`), the two [Nudge](shift.md) functions (`»«`), [Merge](couple.md) (`>`), and [Reshape](reshape.md) (`⥊`). Arrays are value types (or immutable), so that there is no way to "change" the shape or elements of an array. An array with different properties is a different array. As a consequence, arrays are an inductive type, and it's not possible for an array to contain itself, or contain an array that contains itself, and so on. However, it is possible for an array to contain a function or other operation that has access to the array through a variable, and in this sense an array can "know about" itself. |
