diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-10-13 20:31:54 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-10-13 20:31:54 -0400 |
| commit | 5bb8566a1916a7fcccaea3e57181966d7ec9f1bb (patch) | |
| tree | 70f0989afbe739970fec815bdb09fe9546761bbe | |
| parent | 195311657a5eb0a40c1af49de9ffe378a117e0bc (diff) | |
Expand Each description in tutorials
| -rw-r--r-- | docs/tutorial/list.html | 15 | ||||
| -rw-r--r-- | tutorial/list.md | 12 |
2 files changed, 15 insertions, 12 deletions
diff --git a/docs/tutorial/list.html b/docs/tutorial/list.html index 722c7354..1d84ca5b 100644 --- a/docs/tutorial/list.html +++ b/docs/tutorial/list.html @@ -207,17 +207,18 @@ </tr> </table> -<p>The 1-modifier Each (<code><span class='Modifier'>¨</span></code>) applies its operand to every element of a list argument, like <code><span class='Value'>map</span></code> in a functional programming language. With two list arguments, Each pairs the corresponding elements like arithmetic does, or a bit like a <code><span class='Value'>zip</span></code> function (unlike arithmetic, it only goes one level deep). If one argument is a list and one's an atom, the atom is reused every time instead.</p> -<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oy9wqggImFiY2Qi4oC/IkFCQ0RFRiLigL8iMDEiCgoic3RyaW5nIuKAvyJsaXN0IuKAvyJhcnJheSIg4oi+wqggJ3MnCgoiYWJjIiDii4jCqCDijL0gImFiYyI=">↗️</a><pre> <span class='Function'>⌽</span><span class='Modifier'>¨</span> <span class='String'>"abcd"</span><span class='Ligature'>‿</span><span class='String'>"ABCDEF"</span><span class='Ligature'>‿</span><span class='String'>"01"</span> +<p>The 1-modifier Each (<code><span class='Modifier'>¨</span></code>) applies its operand to every element of a list argument, like <code><span class='Value'>map</span></code> in a functional programming language. So here's how we'd reverse each of three lists.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oy9wqggImFiY2Qi4oC/IkFCQ0RFRiLigL8iMDEi">↗️</a><pre> <span class='Function'>⌽</span><span class='Modifier'>¨</span> <span class='String'>"abcd"</span><span class='Ligature'>‿</span><span class='String'>"ABCDEF"</span><span class='Ligature'>‿</span><span class='String'>"01"</span> ⟨ "dcba" "FEDCBA" "10" ⟩ +</pre> +<p>Given two list arguments, Each pairs the corresponding elements—first with first, second with second, and so on, like a <code><span class='Value'>zip</span></code> function. If just one argument's a list and the other's an atom, it reuses the atom in every pair instead. This many-to-many or one-to-many pairing is the same as we saw for arithmetic. But Each only ever goes one level deep while arithmetic keeps going until it reaches a non-list.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=ImFiYyIg4ouIwqggIkFCQyIKCiJzdHJpbmci4oC/Imxpc3Qi4oC/ImFycmF5IiDiiL7CqCAncyc=">↗️</a><pre> <span class='String'>"abc"</span> <span class='Function'>⋈</span><span class='Modifier'>¨</span> <span class='String'>"ABC"</span> +⟨ "aA" "bB" "cC" ⟩ <span class='String'>"string"</span><span class='Ligature'>‿</span><span class='String'>"list"</span><span class='Ligature'>‿</span><span class='String'>"array"</span> <span class='Function'>∾</span><span class='Modifier'>¨</span> <span class='String'>'s'</span> ⟨ "strings" "lists" "arrays" ⟩ - - <span class='String'>"abc"</span> <span class='Function'>⋈</span><span class='Modifier'>¨</span> <span class='Function'>⌽</span> <span class='String'>"abc"</span> -⟨ "ac" "bb" "ca" ⟩ </pre> -<p>Fold (<code><span class='Modifier'>´</span></code>) is the higher-order function also known as reduce or accumulate. It applies its operand function between each pair of elements in a list argument. For example, <code><span class='Function'>+</span><span class='Modifier'>´</span></code> gives the sum of a list and <code><span class='Function'>×</span><span class='Modifier'>´</span></code> gives its product.</p> +<p>Next, Fold (<code><span class='Modifier'>´</span></code>) is the higher-order function also known as reduce or accumulate. The argument has to be a list, and it applies its operand function between all the elements of that list. For example, <code><span class='Function'>+</span><span class='Modifier'>´</span></code> gives the sum of a list and <code><span class='Function'>×</span><span class='Modifier'>´</span></code> gives its product.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=K8K0IDLigL8z4oC/NArDl8K0IDLigL8z4oC/NA==">↗️</a><pre> <span class='Function'>+</span><span class='Modifier'>´</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span> 9 <span class='Function'>×</span><span class='Modifier'>´</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span> @@ -229,7 +230,7 @@ <span class='Number'>1</span><span class='Function'>-</span><span class='Number'>2</span><span class='Function'>-</span><span class='Number'>3</span><span class='Function'>-</span><span class='Number'>4</span><span class='Function'>-</span><span class='Number'>5</span> 3 </pre> -<p>With this evaluation order, <code><span class='Function'>-</span><span class='Modifier'>´</span></code> gives the <em>alternating sum</em> of its argument. Think of it this way: the left argument of each <code><span class='Function'>-</span></code> is a single number, while the right argument is made up of all the numbers to the right subtracted together. So each <code><span class='Function'>-</span></code> flips the sign of every number to its right, and every number is negated by all the <code><span class='Function'>-</span></code>s to its left. The first number (<code><span class='Number'>1</span></code> above) never gets negated, the second is negated once, the third is negated twice, returning it to its original value… the signs alternate.</p> +<p>With this evaluation order, <code><span class='Function'>-</span><span class='Modifier'>´</span></code> gives the <em>alternating sum</em> of its argument, which comes up in math once in a while. Think of it this way: the left argument of each <code><span class='Function'>-</span></code> is a single number, while the right argument is made up of all the numbers to the right subtracted together. So each <code><span class='Function'>-</span></code> flips the sign of every number to its right, and every number is negated by all the <code><span class='Function'>-</span></code>s to its left. The first number (<code><span class='Number'>1</span></code> above) never gets negated, the second is negated once, the third is negated twice, returning it to its original value… the signs alternate.</p> <p><em>Hey, isn't it dissonant that the first, second, and third numbers are negated zero, one, and two times? Not if you call them the zeroth, first, and second…</em></p> <p>You can fold with the Join To function to join several lists together:</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oi+wrQg4p+oICJjb24iLCAiY2F0IiwgImVuYXQiLCAiZSIg4p+p">↗️</a><pre> <span class='Function'>∾</span><span class='Modifier'>´</span> <span class='Bracket'>⟨</span> <span class='String'>"con"</span><span class='Separator'>,</span> <span class='String'>"cat"</span><span class='Separator'>,</span> <span class='String'>"enat"</span><span class='Separator'>,</span> <span class='String'>"e"</span> <span class='Bracket'>⟩</span> diff --git a/tutorial/list.md b/tutorial/list.md index b34587ca..c144a3ac 100644 --- a/tutorial/list.md +++ b/tutorial/list.md @@ -148,15 +148,17 @@ With a left argument `⌽` means Rotate instead, and shifts values over by the s <!--GEN Primitives ⟨"¨%2%Each", "´%5%Fold", "∾%,%Join%Join To"⟩ --> -The 1-modifier Each (`¨`) applies its operand to every element of a list argument, like `map` in a functional programming language. With two list arguments, Each pairs the corresponding elements like arithmetic does, or a bit like a `zip` function (unlike arithmetic, it only goes one level deep). If one argument is a list and one's an atom, the atom is reused every time instead. +The 1-modifier Each (`¨`) applies its operand to every element of a list argument, like `map` in a functional programming language. So here's how we'd reverse each of three lists. ⌽¨ "abcd"‿"ABCDEF"‿"01" - "string"‿"list"‿"array" ∾¨ 's' +Given two list arguments, Each pairs the corresponding elements—first with first, second with second, and so on, like a `zip` function. If just one argument's a list and the other's an atom, it reuses the atom in every pair instead. This many-to-many or one-to-many pairing is the same as we saw for arithmetic. But Each only ever goes one level deep while arithmetic keeps going until it reaches a non-list. + + "abc" ⋈¨ "ABC" - "abc" ⋈¨ ⌽ "abc" + "string"‿"list"‿"array" ∾¨ 's' -Fold (`´`) is the higher-order function also known as reduce or accumulate. It applies its operand function between each pair of elements in a list argument. For example, `+´` gives the sum of a list and `×´` gives its product. +Next, Fold (`´`) is the higher-order function also known as reduce or accumulate. The argument has to be a list, and it applies its operand function between all the elements of that list. For example, `+´` gives the sum of a list and `×´` gives its product. +´ 2‿3‿4 ×´ 2‿3‿4 @@ -166,7 +168,7 @@ To match the order of BQN evaluation, Fold moves over its argument array from ri -´ 1‿2‿3‿4‿5 1-2-3-4-5 -With this evaluation order, `-´` gives the *alternating sum* of its argument. Think of it this way: the left argument of each `-` is a single number, while the right argument is made up of all the numbers to the right subtracted together. So each `-` flips the sign of every number to its right, and every number is negated by all the `-`s to its left. The first number (`1` above) never gets negated, the second is negated once, the third is negated twice, returning it to its original value… the signs alternate. +With this evaluation order, `-´` gives the *alternating sum* of its argument, which comes up in math once in a while. Think of it this way: the left argument of each `-` is a single number, while the right argument is made up of all the numbers to the right subtracted together. So each `-` flips the sign of every number to its right, and every number is negated by all the `-`s to its left. The first number (`1` above) never gets negated, the second is negated once, the third is negated twice, returning it to its original value… the signs alternate. *Hey, isn't it dissonant that the first, second, and third numbers are negated zero, one, and two times? Not if you call them the zeroth, first, and second…* |
