From a25cb2b0bf26033c9bc778d816618a752d015d99 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 5 Jul 2022 16:46:42 -0400 Subject: Somehow, all the docs have now been edited --- docs/doc/map.html | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'docs/doc/map.html') diff --git a/docs/doc/map.html b/docs/doc/map.html index e91b4689..652651ca 100644 --- a/docs/doc/map.html +++ b/docs/doc/map.html @@ -62,7 +62,13 @@ ⟨ "0⊑𝕩" "1⊑𝕩" "2⊑𝕩" ⟩

The applications are performed in index order: index 00, then 01, 02 and so on, until 10. This can affect a program where the operand has side effects, such as the following one that appends its argument to o.

-↗️
    o⟨⟩  {o<𝕩}¨ "index""order"  o
+↗️
    ["index","order"]
+┌─       
+╵"index  
+  order" 
+        ┘
+
+    o⟨⟩  {o<𝕩}¨ ["index","order"]  o
 "indexorder"
 

When an array is displayed, index order is the same as the top-to-bottom, left-to-right reading order of English. It's also the same as the ordering of Deshape's result, so that here o ends up being 𝕩. The dyadic cases described in the following sections will also have a defined evaluation order, but it's not as easy to describe it in terms of the arguments: instead, the result elements are produced in index order.

@@ -126,7 +132,7 @@

The Table modifier applies its operand function to every possible combination of one element from 𝕨 and one from 𝕩, sort of like a structure-preserving and function-applying Cartesian product. Below, it combines a length-3 list and a length-5 list into a shape 35 table.

-↗️
    "ABC"  "01234"
+↗️
    "ABC"  "01234"
 ┌─                          
 ╵ "A0" "A1" "A2" "A3" "A4"  
   "B0" "B1" "B2" "B3" "B4"  
@@ -145,7 +151,7 @@
                    ┘
 

The arguments don't have to be lists (that is, rank 1). There's no restriction on their shapes at all! Much like the result shape is mn if 𝕨 is a list of length m and 𝕩 is a list of length n, the result shape for an array 𝕨 of shape r and 𝕩 of shape s is rs.

-↗️
    "A ""B "  "the""first""row""and""the""second"
+↗️
    "A ""B "  ["the""first""row","and""the""second"]
 ┌─                              
 ╎ "A the" "A first" "A row"     
   "A and" "A the"   "A second"  
@@ -154,7 +160,7 @@
   "B and" "B the"   "B second"  
                                ┘
 
-     "A ""B "  "the""first""row""and""the""second"
+     "A ""B "  ["the""first""row","and""the""second"]
 ⟨ 2 2 3 ⟩
 

Except for the more sophisticated shape, this result is exactly what you'd get if you deshaped each argument to a list. In each case, every element of 𝕨 is visited in turn, and each time the element is paired with every element of 𝕩.

@@ -210,31 +216,31 @@

Given two arguments of matching shapes, Each performs what's sometimes called a "zip", matching each element of 𝕨 to the corresponding element of 𝕩.

-↗️
    "ABCD" ¨ "0123"
+↗️
    "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 Reorder Axes.

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

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"
+↗️
    "ABC" ¨ "01234"
 Error: Mapping: Expected equal shape prefix (⟨3⟩ ≡ ≢𝕨, ⟨5⟩ ≡ ≢𝕩)
 

Arguments can have any shape as long as the axis lengths match up. As with Table, the result elements don't depend on these shapes but the result shape does.

-↗️
    [203010,504060] +¨ 210321
+↗️
    [203010,504060] +¨ [210,321]
 ┌─                               
 ╵ ⟨ 20 21 ⟩    ⟨ 30 ⟩    ⟨⟩      
   ⟨ 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 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
+↗️
     (026@) ¨ 010  # Too small
 Error: Mapping: Expected equal shape prefix (0‿2‿6 ≡ ≢𝕨, 0‿1 ≡ ≢𝕩)
 
-     (026@) ¨ 030  # Too large
+     (026@) ¨ 030  # Too large
 Error: Mapping: Expected equal shape prefix (0‿2‿6 ≡ ≢𝕨, 0‿3 ≡ ≢𝕩)
 
-     (026@) ¨ 020  # Just right
+     (026@) ¨ 020  # Just right
 ⟨ 0 2 6 ⟩
 
-- cgit v1.2.3