From 9e952ffd79f704ffd8b0e327a7c5afbaead7a213 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 3 Dec 2020 14:53:45 -0500 Subject: Code blocks can have function results now --- doc/functional.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'doc/functional.md') diff --git a/doc/functional.md b/doc/functional.md index 1d55e8b8..49fb0c25 100644 --- a/doc/functional.md +++ b/doc/functional.md @@ -109,25 +109,22 @@ First, let's look at the basics: a small program that has functions as its argum We can pass it the exponential function as an argument by giving it the name `Exp` and then referring to it in lowercase (that is, in a subject role). The result is a train that adds 1 to *e*-1 times the argument. + Lin โ† { v0โ†๐•0 โ‹„ v0+((๐•1)-v0)ร—โŠข } Exp โ† โ‹† Lin exp - (1 + (1.71828182845905 ร— โŠข)) As with all functions, the result of `Lin` has a subject role. To use it as a function, we give it a name and then use that name with an uppercase spelling. expLin โ† Lin exp ExpLin 5 - 9.59140914229523 A tricker but more compact method is to use the 1-modifier `{๐”ฝ}`, as the input to a modifier can have a subject or function role but its output always has a function role. (Lin exp){๐”ฝ} 5 - 9.59140914229523 Not the most accurate approximation, though. Exp 5 - 148.413159102577 Note also in this case that we could have used a modifier with a very similar definition to `Lin`. The modifier is identical in definition except that `๐•` is replaced with `๐”ฝ`. @@ -138,15 +135,14 @@ Note also in this case that we could have used a modifier with a very similar de Its call syntax is simpler as well. In other cases, however, the function version might be preferable, for example when dealing with arrays of functions or many arguments including a function. + _lin โ†ฉ { v0โ†๐”ฝ0 โ‹„ v0+((๐”ฝ1)-v0)ร—โŠข } Exp _lin 5 - 9.59140914229523 ### Arrays of functions It's very convenient to put a function in an array, which is fortunate because this is one of the most important uses of functions as subjects. Here's an example of an array of functions with a reduction applied to it, composing them together. {๐•Žโˆ˜๐•}ยด โ‹†โ€ฟ-โ€ฟ(ร—หœ) - โ‹†โˆ˜(-โˆ˜(ร—หœ)) Like any function, this one can be given a name and then called. A quirk of this way of defining a function is that it has a subject role (it's the result of the function `{๐•Žโˆ˜๐•}ยด`) and so must be defined with a lowercase name. -- cgit v1.2.3