aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-12-03 14:53:45 -0500
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-12-03 15:05:47 -0500
commit9e952ffd79f704ffd8b0e327a7c5afbaead7a213 (patch)
tree3e016e48c563290d732dc0dc1bc8d0e0c384d1b2
parentfff1c8c635ca370f5ab306936a97b4c3f21a8619 (diff)
Code blocks can have function results now
-rw-r--r--doc/functional.md8
-rw-r--r--docs/doc/functional.html26
2 files changed, 16 insertions, 18 deletions
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.
diff --git a/docs/doc/functional.html b/docs/doc/functional.html
index 7e3b3900..fbba17dd 100644
--- a/docs/doc/functional.html
+++ b/docs/doc/functional.html
@@ -76,22 +76,23 @@
<span class='Brace'>}</span>
</pre>
<p>We can pass it the exponential function as an argument by giving it the name <code><span class='Function'>Exp</span></code> and then referring to it in lowercase (that is, in a subject role). The result is a train that adds 1 to <em>e</em>-1 times the argument.</p>
-<pre> <span class='Function'>Exp</span> <span class='Gets'>โ†</span> <span class='Function'>โ‹†</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=TGluIOKGkCB7IHYw4oaQ8J2VjzAg4ouEIHYwKygo8J2VjzEpLXYwKcOX4oqiIH0KRXhwIOKGkCDii4YKTGluIGV4cA==">โ†—๏ธ</a><pre> <span class='Function'>Lin</span> <span class='Gets'>โ†</span> <span class='Brace'>{</span> <span class='Value'>v0</span><span class='Gets'>โ†</span><span class='Function'>๐•</span><span class='Number'>0</span> <span class='Separator'>โ‹„</span> <span class='Value'>v0</span><span class='Function'>+</span><span class='Paren'>((</span><span class='Function'>๐•</span><span class='Number'>1</span><span class='Paren'>)</span><span class='Function'>-</span><span class='Value'>v0</span><span class='Paren'>)</span><span class='Function'>ร—โŠข</span> <span class='Brace'>}</span>
+ <span class='Function'>Exp</span> <span class='Gets'>โ†</span> <span class='Function'>โ‹†</span>
<span class='Function'>Lin</span> <span class='Value'>exp</span>
-<span class='Paren'>(</span><span class='Number'>1</span> <span class='Function'>+</span> <span class='Paren'>(</span><span class='Number'>1.71828182845905</span> <span class='Function'>ร—</span> <span class='Function'>โŠข</span><span class='Paren'>))</span>
+1+1.718281828459045ร—โŠข
</pre>
<p>As with all functions, the result of <code><span class='Function'>Lin</span></code> has a subject role. To use it as a function, we give it a name and then use that name with an uppercase spelling.</p>
-<pre> <span class='Value'>expLin</span> <span class='Gets'>โ†</span> <span class='Function'>Lin</span> <span class='Value'>exp</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=ZXhwTGluIOKGkCBMaW4gZXhwCkV4cExpbiA1">โ†—๏ธ</a><pre> <span class='Value'>expLin</span> <span class='Gets'>โ†</span> <span class='Function'>Lin</span> <span class='Value'>exp</span>
<span class='Function'>ExpLin</span> <span class='Number'>5</span>
-<span class='Number'>9.59140914229523</span>
+9.591409142295225
</pre>
<p>A tricker but more compact method is to use the 1-modifier <code><span class='Brace'>{</span><span class='Function'>๐”ฝ</span><span class='Brace'>}</span></code>, as the input to a modifier can have a subject or function role but its output always has a function role.</p>
-<pre> <span class='Paren'>(</span><span class='Function'>Lin</span> <span class='Value'>exp</span><span class='Paren'>)</span><span class='Brace'>{</span><span class='Function'>๐”ฝ</span><span class='Brace'>}</span> <span class='Number'>5</span>
-<span class='Number'>9.59140914229523</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KExpbiBleHApe/CdlL19IDU=">โ†—๏ธ</a><pre> <span class='Paren'>(</span><span class='Function'>Lin</span> <span class='Value'>exp</span><span class='Paren'>)</span><span class='Brace'>{</span><span class='Function'>๐”ฝ</span><span class='Brace'>}</span> <span class='Number'>5</span>
+9.591409142295225
</pre>
<p>Not the most accurate approximation, though.</p>
-<pre> <span class='Function'>Exp</span> <span class='Number'>5</span>
-<span class='Number'>148.413159102577</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=RXhwIDU=">โ†—๏ธ</a><pre> <span class='Function'>Exp</span> <span class='Number'>5</span>
+148.4131591025766
</pre>
<p>Note also in this case that we could have used a modifier with a very similar definition to <code><span class='Function'>Lin</span></code>. The modifier is identical in definition except that <code><span class='Function'>๐•</span></code> is replaced with <code><span class='Function'>๐”ฝ</span></code>.</p>
<pre><span class='Modifier'>_lin</span> <span class='Gets'>โ†ฉ</span> <span class='Brace'>{</span>
@@ -100,13 +101,14 @@
<span class='Brace'>}</span>
</pre>
<p>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.</p>
-<pre> <span class='Function'>Exp</span> <span class='Modifier'>_lin</span> <span class='Number'>5</span>
-<span class='Number'>9.59140914229523</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=X2xpbiDihqkgeyB2MOKGkPCdlL0wIOKLhCB2MCsoKPCdlL0xKS12MCnDl+KKoiB9CkV4cCBfbGluIDU=">โ†—๏ธ</a><pre> <span class='Modifier'>_lin</span> <span class='Gets'>โ†ฉ</span> <span class='Brace'>{</span> <span class='Value'>v0</span><span class='Gets'>โ†</span><span class='Function'>๐”ฝ</span><span class='Number'>0</span> <span class='Separator'>โ‹„</span> <span class='Value'>v0</span><span class='Function'>+</span><span class='Paren'>((</span><span class='Function'>๐”ฝ</span><span class='Number'>1</span><span class='Paren'>)</span><span class='Function'>-</span><span class='Value'>v0</span><span class='Paren'>)</span><span class='Function'>ร—โŠข</span> <span class='Brace'>}</span>
+ <span class='Function'>Exp</span> <span class='Modifier'>_lin</span> <span class='Number'>5</span>
+9.591409142295225
</pre>
<h3 id="arrays-of-functions">Arrays of functions</h3>
<p>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.</p>
-<pre> <span class='Brace'>{</span><span class='Function'>๐•Ž</span><span class='Modifier2'>โˆ˜</span><span class='Function'>๐•</span><span class='Brace'>}</span><span class='Modifier'>ยด</span> <span class='Function'>โ‹†</span><span class='Ligature'>โ€ฟ</span><span class='Function'>-</span><span class='Ligature'>โ€ฟ</span><span class='Paren'>(</span><span class='Function'>ร—</span><span class='Modifier'>หœ</span><span class='Paren'>)</span>
-<span class='Function'>โ‹†</span><span class='Modifier2'>โˆ˜</span><span class='Paren'>(</span><span class='Function'>-</span><span class='Modifier2'>โˆ˜</span><span class='Paren'>(</span><span class='Function'>ร—</span><span class='Modifier'>หœ</span><span class='Paren'>))</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=e/CdlY7iiJjwnZWPfcK0IOKLhuKAvy3igL8ow5fLnCk=">โ†—๏ธ</a><pre> <span class='Brace'>{</span><span class='Function'>๐•Ž</span><span class='Modifier2'>โˆ˜</span><span class='Function'>๐•</span><span class='Brace'>}</span><span class='Modifier'>ยด</span> <span class='Function'>โ‹†</span><span class='Ligature'>โ€ฟ</span><span class='Function'>-</span><span class='Ligature'>โ€ฟ</span><span class='Paren'>(</span><span class='Function'>ร—</span><span class='Modifier'>หœ</span><span class='Paren'>)</span>
+โ‹†โˆ˜(-โˆ˜(ร—หœ))
</pre>
<p>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 <code><span class='Brace'>{</span><span class='Function'>๐•Ž</span><span class='Modifier2'>โˆ˜</span><span class='Function'>๐•</span><span class='Brace'>}</span><span class='Modifier'>ยด</span></code>) and so must be defined with a lowercase name.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=Z2F1c3Mg4oaQIHvwnZWO4oiY8J2Vj33CtCDii4bigL8t4oC/KMOXy5wpCkdhdXNzIDI=">โ†—๏ธ</a><pre> <span class='Value'>gauss</span> <span class='Gets'>โ†</span> <span class='Brace'>{</span><span class='Function'>๐•Ž</span><span class='Modifier2'>โˆ˜</span><span class='Function'>๐•</span><span class='Brace'>}</span><span class='Modifier'>ยด</span> <span class='Function'>โ‹†</span><span class='Ligature'>โ€ฟ</span><span class='Function'>-</span><span class='Ligature'>โ€ฟ</span><span class='Paren'>(</span><span class='Function'>ร—</span><span class='Modifier'>หœ</span><span class='Paren'>)</span>