aboutsummaryrefslogtreecommitdiff
path: root/tutorial/variable.md
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-09-26 21:48:54 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-09-26 21:48:54 -0400
commit84bf304c69c8fd662d2ee0d4770fc67981e4b222 (patch)
treecd44118907df0c8ecd9524418d96cf6ff424e9b0 /tutorial/variable.md
parent008894473a5d2177e5683719b718e0acefd515bc (diff)
Use monadic modified assignment in the tutorial
Diffstat (limited to 'tutorial/variable.md')
-rw-r--r--tutorial/variable.md10
1 files changed, 8 insertions, 2 deletions
diff --git a/tutorial/variable.md b/tutorial/variable.md
index 3e3f7467..71f28789 100644
--- a/tutorial/variable.md
+++ b/tutorial/variable.md
@@ -201,12 +201,18 @@ But this changes the value of `a` to a completely unrelated value. What if I wan
a ∾˜↩ 0‿1
-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"
a ⌽∘⊣↩ @
+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 ⌽↩
+
+ a 4⊸-↩ # And back again
+
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
@@ -215,4 +221,4 @@ Notice that there's no need for parentheses: modifiers bind more strongly than t
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⊸↑)↩