From 84bf304c69c8fd662d2ee0d4770fc67981e4b222 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sun, 26 Sep 2021 21:48:54 -0400 Subject: Use monadic modified assignment in the tutorial --- docs/tutorial/variable.html | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/tutorial/variable.html b/docs/tutorial/variable.html index e8a1f06e..226b54ae 100644 --- a/docs/tutorial/variable.html +++ b/docs/tutorial/variable.html @@ -304,13 +304,20 @@ ERROR ↗️
    a ˜ 01
 ⟨ 0 1 2 3 4 ⟩
 
-

But what about functions with only one argument? The syntax isn't the best, but at least it's possible. There still needs to be a value on the right side of the assignment even if it'll be ignored; I use the null character @ for this. Then to turn a function that takes one argument into one that takes two, we can compose it with a function that takes two arguments and returns one of them. The left one, since the variable to modify is on the left hand side. Perhaps… Left? ()?

+

But what about functions with only one argument? It's possible to do this using a dummy right argument such as the null character, @. To turn a function that takes one argument into one that takes two, we can compose it with a function that takes two arguments and returns one of them. The left one, since the variable to modify is on the left hand side. Perhaps… Left? ()?

↗️
    "abcd"  "wxyz"
 "dcba"
 
     a  @
 ⟨ 4 3 2 1 0 ⟩
 
+

But fortunately, there's a simpler syntax as well: write your one-argument function before with no right hand side. Bit of a Yoda vibe: "a reversed is".

+↗️
    a 
+⟨ 0 1 2 3 4 ⟩
+
+    a 4-           # And back again
+⟨ 4 3 2 1 0 ⟩
+

Notice that there's no need for parentheses: modifiers bind more strongly than the assignment character. Now what if we want to decrease the last two elements of a? That is, we want to compute the following array while storing it in a.

↗️
    -4(¯2) a
 ⟨ 4 3 2 ¯3 ¯4 ⟩
@@ -319,6 +326,6 @@ ERROR
 ⟨ 4 3 2 1 0 ⟩
 

The code to do this looks the same as what we did with Reverse (). Again we don't have to parenthesize the function, because modifiers associate from left to right, so Under () binds to its operands before Compose () does.

-↗️
    a -4(¯2) @
+↗️
    a -4(¯2)
 ⟨ 4 3 2 ¯3 ¯4 ⟩
 
-- cgit v1.2.3