From 7e5d0fcc39fd8a683fc7010af064849b454b432b Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 4 Jun 2022 17:40:31 -0400 Subject: Further editing --- docs/doc/map.html | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'docs/doc/map.html') diff --git a/docs/doc/map.html b/docs/doc/map.html index f84421cf..396b0a48 100644 --- a/docs/doc/map.html +++ b/docs/doc/map.html @@ -6,7 +6,7 @@

Mapping modifiers

Mapping a function over an array means to call it on each element of that array, creating an array of results. It's also possible to map over two arrays, applying the function to various choices of one element from each, but there's no longer a single correct way to iterate over these elements.

-

BQN has two 1-modifiers to map over arrays: Each (¨) and Table (). On two arguments, Table applies its operand to all combinations of elements while Each creates a one-to-one or one-to-many matching. Since they apply to elements, these modifiers are different from Cells (˘) or its generalization Rank (), which apply the function to array cells. The modifier Depth () is a generalization of Each, so that ¨ is ¯1; however, it can't be used to implement Table without some additional array operations.

+

As a result, BQN has two 1-modifiers to map over arrays: Each (¨) and Table (). On two arguments, Table applies its operand to all combinations of elements while Each creates a one-to-one or one-to-many matching. Since they apply to elements, these modifiers are different from Cells (˘) or its generalization Rank (), which apply the function to array cells. The modifier Depth () is a generalization of Each, so that ¨ is ¯1; however, it can't be used to implement Table without some additional array operations.

One-argument mapping

@@ -133,7 +133,7 @@ "C0" "C1" "C2" "C3" "C4" ┘ -

Its name comes from the "multiplication table" or "times table" often used to teach arithmetic, and with it you can easily make such a table, by repeating the same argument with Self (˜):

+

Its name comes from the "multiplication table" or "times table" often used to teach arithmetic, and with it you can easily make such a table, by repeating the same argument with Self (˜):

↗️
    ×⌜˜ 1+↕6
 ┌─                  
 ╵ 1  2  3  4  5  6  
@@ -213,11 +213,11 @@
 ↗️
    "ABCD" ¨ "0123"
 ⟨ "A0" "B1" "C2" "D3" ⟩
 
-

This makes for a lot fewer applications than Table. Only the diagonal elements from Table's result are seen, as we can check with Transpose.

+

This makes for a lot fewer applications than Table. Only the diagonal elements from Table's result are seen, as we can check with Reorder Axes.

↗️
    00  "ABCD"  "0123"
 ⟨ "A0" "B1" "C2" "D3" ⟩
 
-

If the argument lengths don't match then Each gives an error. This contrasts with zip in many languages, which drops elements from the longer argument (this is natural for linked lists). This flexibility is rarely wanted in BQN, and having an error right away saves debugging time.

+

If the argument lengths don't match then Each gives an error. This differs from zip in many languages, which drops elements from the longer argument (this is natural for linked lists). This flexibility is rarely wanted in BQN, and having an error right away saves debugging time.

↗️
    "ABC" ¨ "01234"
 Error: Mapping: Expected equal shape prefix (⟨3⟩ ≡ ≢𝕨, ⟨5⟩ ≡ ≢𝕩)
 
@@ -228,12 +228,13 @@ ⟨ 50 51 52 ⟩ ⟨ 40 41 ⟩ ⟨ 60 ⟩ ┘
-

But arguments don't have to have exactly the same shape: just the same length along corresponding axes. These axes are matched up according to the leading axis convention, so that one argument's shape has to be a prefix of the other's. With equal ranks, the shapes do have to match as we've seen above.

-↗️
     (026@) ¨ 010  # Too small
+

But arguments don't have to have exactly the same shape: just the same length along corresponding axes. These axes are matched up by leading axis agreement, so that one argument's shape has to be a prefix of the other's. With equal ranks, the shapes do have to match as we've seen above.

+↗️
     (026@) ¨ 010  # Too small
 Error: Mapping: Expected equal shape prefix (0‿2‿6 ≡ ≢𝕨, 0‿1 ≡ ≢𝕩)
-     (026@) ¨ 020  # Just right
-⟨ 0 2 6 ⟩
+
      (026@) ¨ 030  # Too large
 Error: Mapping: Expected equal shape prefix (0‿2‿6 ≡ ≢𝕨, 0‿3 ≡ ≢𝕩)
+
+     (026@) ¨ 020  # Just right
+⟨ 0 2 6 ⟩
 
-

Leading axis agreement is described further here.

-- cgit v1.2.3