From 60d51c85dd306989e919e91e37d9b94fe60411c2 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 22 Aug 2020 09:47:16 -0400 Subject: Add REPL links to documentation code blocks --- docs/doc/leading.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'docs/doc/leading.html') diff --git a/docs/doc/leading.html b/docs/doc/leading.html index e86c57f7..92200f77 100644 --- a/docs/doc/leading.html +++ b/docs/doc/leading.html @@ -5,7 +5,7 @@

Monadic functions

Manipulating cells

Most non-scalar monadic functions work only on the first axis of the argument—that is, they treat it as a list of its major cells. The function Length () counts these major cells, while Prefixes (), Suffixes (), Reverse (), and First Cell () move them around. The Insert (˝) and Scan (`) modifiers also yield functions that work along the first axis; in contrast, Reduce (´) requires its argument to be a list, as it works on elements.

-
     a  32  "abcdef"  # An array with three major cells
+↗️
     a  32  "abcdef"  # An array with three major cells
 ┌─    
 ╵"ab  
   cd  
@@ -27,7 +27,7 @@
      ┘
 

To use these functions on another axis, use the Rank () or Cells (˘) modifier to find the one you want. For a rank 2 array like a, the most you'll ever need is a single ˘, because a function works on axis 0 by default, and there's only one other axis.

-
    ˘ a                  # First column
+↗️
    ˘ a                  # First column
 "ace"
     ˘ a                  # Swap the columns
 ┌─    
@@ -43,7 +43,7 @@
      ┘
 

In these three cases above, the results are the same as you would get from transposing before and after (this has no effect on the result of ˘, since it has rank 1). But in the following cases, the structure is quite different: a is a list of matrices while ˘a is a matrix of lists. This is because the functions , , and ` leave the trailing axis structure intact ( removes one axis); taking into account that Rank or Cells always preserves the leading or frame axes, all axes are preserved (except the one removed by ). In contrast, Prefixes or Suffixes pushes some axes down in depth, and the number of axes that are pushed down in this way changes with the rank of application. More precisely, these functions move axes after the first from the argument itself to result elements, and create two axes from the first axis, with one of them forming the sole result axis and the other joining the rest as an element axis.

-
     a                   # Prefixes of a:    ranks 1|2
+↗️
     a                   # Prefixes of a:    ranks 1|2
 ┌─                             
 · 0‿2⥊⟨⟩ ┌─     ┌─     ┌─      
          ╵"ab"  ╵"ab   ╵"ab    
@@ -67,7 +67,7 @@
      ┘
 

Solo (), something of a maverick, manages to act on zero leading axes of its argument by creating the first axis of the result instead. Because it doesn't need any axis to work, it can go in front of either axis but also past the last one by working with rank 0, a case where most array functions would give an error.

-
      a                 # Solo adds a length-1 axis
+↗️
      a                 # Solo adds a length-1 axis
 ⟨ 1 3 2 ⟩
     a    a             # First Cell undoes this
 1
@@ -78,7 +78,7 @@
 

Comparing cells

The functions in the last section manipulate cells in the same way regardless of what data they contain. Other functions compare cells to each other, either testing whether they match or how they are ordered relative to one another. The two Grade functions ⍋⍒, and the self-comparison functions Unique Mask () and Occurrence Count (), each give a list result, with one number for each cell. We can see below that Occurrence Count returns the same results even as we make the argument cells more complicated, because the changes made preserve the matching of cells.

-
    s  "abracadabra"
+↗️
    s  "abracadabra"
      s
 ⟨ 0 0 0 1 0 2 0 3 1 1 4 ⟩
      ˘ s
@@ -87,7 +87,7 @@
 ⟨ 0 0 0 1 0 2 0 3 1 1 4 ⟩
 

The two Sort functions ∧∨ and Deduplicate () move cells around based on their ordering. The length of Deduplicate's result depends on how many unique cells the argument has, so you'd better be careful if you want to apply it to argument cells! However, the result of sorting has the same shape as the argument, so it can always safely be applied at any rank, for example to the rows of an array.

-
     b  45  4
+↗️
     b  45  4
 ┌─           
 ╵ 0 1 2 3 0  
   1 2 3 0 1  
@@ -129,7 +129,7 @@
 
 
 

Functions such as Take and Drop use a single number per axis. When the left argument is a list of numbers, they apply to initial axes. Observing the operation of Rotate on the result of Range is instructive:

-
    21  35
+↗️
    21  35
 ┌─                                         
 ╵ ⟨ 2 1 ⟩ ⟨ 2 2 ⟩ ⟨ 2 3 ⟩ ⟨ 2 4 ⟩ ⟨ 2 0 ⟩  
   ⟨ 0 1 ⟩ ⟨ 0 2 ⟩ ⟨ 0 3 ⟩ ⟨ 0 4 ⟩ ⟨ 0 0 ⟩  
@@ -137,13 +137,13 @@
                                           ┘
 

The array is shifted once to the left and twice upward, so that the first index (by ravel order) is now 21⌽↕35 ←→ 21. To see how values are matched to leading axes, we can look at how Drop changes the shape of its argument:

-
     32  7777"abc"
+↗️
     32  7777"abc"
 ⟨ 4 5 7 7 ⟩
 

Functions with single-axis depth 1 tend to be more complicated; see for example Group.

Leading axis agreement

Scalar functions, and the Each (¨) and Depth () modifiers, use leading axis agreement to match their arguments together. All axes of the lower-rank argument are matched with the leading axes of the higher-rank one, and axes matched together must have the same length. After pairing axes in this way, a single element of the lower-rank argument might correspond to any number of elements of the higher-rank one. It's reused for each of those corresponding elements.

-
     x  324  60     # A rank-3 array
+↗️
     x  324  60     # A rank-3 array
 ┌─             
 ╎  0  1  2  3  
    4  5  6  7  
-- 
cgit v1.2.3