aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2022-10-13 20:31:54 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2022-10-13 20:31:54 -0400
commit5bb8566a1916a7fcccaea3e57181966d7ec9f1bb (patch)
tree70f0989afbe739970fec815bdb09fe9546761bbe /docs
parent195311657a5eb0a40c1af49de9ffe378a117e0bc (diff)
Expand Each description in tutorials
Diffstat (limited to 'docs')
-rw-r--r--docs/tutorial/list.html15
1 files changed, 8 insertions, 7 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'>&quot;abcd&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;ABCDEF&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;01&quot;</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'>&quot;abcd&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;ABCDEF&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;01&quot;</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'>&quot;abc&quot;</span> <span class='Function'>⋈</span><span class='Modifier'>¨</span> <span class='String'>&quot;ABC&quot;</span>
+⟨ "aA" "bB" "cC" ⟩
<span class='String'>&quot;string&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;list&quot;</span><span class='Ligature'>‿</span><span class='String'>&quot;array&quot;</span> <span class='Function'>∾</span><span class='Modifier'>¨</span> <span class='String'>'s'</span>
⟨ "strings" "lists" "arrays" ⟩
-
- <span class='String'>&quot;abc&quot;</span> <span class='Function'>⋈</span><span class='Modifier'>¨</span> <span class='Function'>⌽</span> <span class='String'>&quot;abc&quot;</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'>&quot;con&quot;</span><span class='Separator'>,</span> <span class='String'>&quot;cat&quot;</span><span class='Separator'>,</span> <span class='String'>&quot;enat&quot;</span><span class='Separator'>,</span> <span class='String'>&quot;e&quot;</span> <span class='Bracket'>⟩</span>