From 5bb8566a1916a7fcccaea3e57181966d7ec9f1bb Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 13 Oct 2022 20:31:54 -0400 Subject: Expand Each description in tutorials --- docs/tutorial/list.html | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'docs/tutorial') 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 @@ -

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.

-↗️
    ¨ "abcd""ABCDEF""01"
+

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"
 ⟨ "dcba" "FEDCBA" "10" ⟩
+
+

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"
+⟨ "aA" "bB" "cC" ⟩
 
     "string""list""array" ¨ 's'
 ⟨ "strings" "lists" "arrays" ⟩
-
-    "abc" ¨  "abc"
-⟨ "ac" "bb" "ca" ⟩
 
-

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.

↗️
    +´ 234
 9
     ×´ 234
@@ -229,7 +230,7 @@
     1-2-3-4-5
 3
 
-

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…

You can fold with the Join To function to join several lists together:

↗️
    ´  "con", "cat", "enat", "e" 
-- 
cgit v1.2.3