From 7bf2aa4054b8378a76dff63acdccbcdad91f68e6 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 7 Aug 2021 20:41:31 -0400 Subject: BREAKING: Don't allow First of empty or reshaping empty to non-empty --- docs/doc/fill.html | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'docs/doc/fill.html') diff --git a/docs/doc/fill.html b/docs/doc/fill.html index 5ef9baf1..843e80e8 100644 --- a/docs/doc/fill.html +++ b/docs/doc/fill.html @@ -6,7 +6,7 @@

Fill elements

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 () when a value in 𝕨 is larger than the corresponding length in 𝕩, by the two Nudge functions (»«) when 𝕩 is non-empty, and by First () and Reshape () when 𝕩 is empty. Except for these specific cases, the fill value an array has can't affect the program. The result of Match () doesn't depend on fills, and any attempt to compute a fill can't cause side effects.

+

Fills are used by Take () when a value in 𝕨 is larger than the corresponding length in 𝕩, by the two Nudge functions (»«) when 𝕩 is non-empty, and by Reshape () when 𝕨 contains . Except for these specific cases, the fill value an array has can't affect the program. The result of Match () doesn't depend on fills, and any attempt to compute a fill can't cause side effects.

Using fills

For the examples in this section we'll use the fact that an all-number array usually has 0 as a fill while a string has ' ' (BQN maintains fills alongside array values rather than deriving them from arrays, so it's possible to construct arrays where this isn't true, but this probably wouldn't happen in ordinary code).

Take () and Nudge (»«) in either direction use the fill for padding, to extend the array past its boundary. For example, 𝕨𝕩 will add elements to one side when a number in |𝕨 is larger than the corresponding length in 𝕩.

@@ -26,18 +26,15 @@ »⟨⟩ # Fill not needed ⟨⟩ -

First () and Reshape () use the fill when 𝕩 is empty, and in the case of Reshape only when the result needs to be non-empty.

-↗️
     ""
-' '
-
-    4 ¨ 0, ""
-⟨ ⟨ 0 0 0 0 ⟩ "    " ⟩
-
-    03  ⟨⟩  # Fill not needed
-↕0‿3
+

Reshape () uses the fill when 𝕨 contains and the product of the rest of 𝕨 doesn't evenly divide the number of elements in 𝕩.

+↗️
    8  "completepart"
+┌─          
+╵"complete  
+  part    " 
+           ┘
 
-

If for some reason you need to find an array's fill element, the easiest way is 0a.

-↗️
    0"string"
+

If for some reason you need to find an array's fill element, the easiest general way is probably ⊑»1↑⥊a.

+↗️
    ⊑»1↑⥊"string"
 ' '
 

How fills are computed

-- cgit v1.2.3