aboutsummaryrefslogtreecommitdiff
path: root/docs/doc
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2022-07-17 22:13:00 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2022-07-17 22:13:48 -0400
commita26bd4e58c96734c142e0a79f4839d2e1c006fa1 (patch)
treeda797e53908f214359da0a53367ab2b440e04d1b /docs/doc
parent9095821c40b1e233065f5ec5eead50543bdbbfdf (diff)
Section on ambivalence in tacit code
Diffstat (limited to 'docs/doc')
-rw-r--r--docs/doc/tacit.html5
1 files changed, 4 insertions, 1 deletions
diff --git a/docs/doc/tacit.html b/docs/doc/tacit.html
index ef2483c6..3a2baaef 100644
--- a/docs/doc/tacit.html
+++ b/docs/doc/tacit.html
@@ -229,6 +229,9 @@
</span>3.5
</pre>
<p>For more complicated &quot;if-else&quot; or &quot;select&quot; type conditionals, use <a href="choose.html">Choose</a> (<code><span class='Modifier2'>◶</span></code>). Watch for ordering here: <code><span class='Function'>F</span><span class='Modifier2'>◶</span><span class='Bracket'>⟨</span><span class='Function'>G0</span><span class='Separator'>,</span><span class='Function'>G1</span><span class='Bracket'>⟩</span></code> puts the two parts in the opposite order to Repeat, and list element 1 comes after element 0 even though it might seem more intuitive for the &quot;true&quot; value to come first.</p>
+<h2 id="valences"><a class="header" href="#valences">Valences</a></h2>
+<p>An ambivalent function is one that can take one or two arguments. Tacit code has a hot-and-cold kind of relationship with it. In cases that fit well with Atop, Over, and trains, it tends to work very well. In others, it might <a href="../commentary/problems.html#cant-always-transfer-ambivalence-in-tacit-code">not work</a> at all. An example is the <code><span class='Brace'>{</span><span class='Value'>𝕨</span><span class='Function'>𝔽𝔾</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code> combinator: there's just no tacit equivalent. However, any ambivalent <em>function</em> can still be represented, because <a href="valences.html">Valences</a> (<code><span class='Modifier2'>⊘</span></code>) combines a separate monadic and dyadic case.</p>
+<p>When designing complex ambivalent functions, it's often best to mix tacit programming with blocks. I usually think of the block as the base for this, since <code><span class='Value'>𝕨</span></code> tends to work with, and might put small tacit functions like <code><span class='Function'>⊢</span><span class='Modifier2'>⊘</span><span class='Function'>∾</span></code> inside, or tack on shared functionality such as <code><span class='Function'>⌽</span><span class='Modifier2'>∘</span><span class='Value'>…</span></code> on the outside.</p>
<h2 id="example-combinations"><a class="header" href="#example-combinations">Example: combinations</a></h2>
<p>As an example, we'll look at the following <a href="https://en.wikipedia.org/wiki/Binomial_coefficient">combinations function</a> implementation from bqncrate (substituting the conventional <code><span class='Value'>k</span></code> and <code><span class='Value'>n</span></code> in for <code><span class='Value'>i0</span></code> and <code><span class='Value'>j0</span></code>):</p>
<pre><span class='Value'>k</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><span class='Number'>1</span><span class='Modifier2'>⊸</span><span class='Function'>+</span><span class='Paren'>)</span><span class='Modifier2'>⟜</span><span class='Function'>↕</span><span class='Modifier'>˜</span><span class='Value'>n</span> <span class='Comment'># Number of unordered selections (combinations) of k items from n choices
@@ -247,7 +250,7 @@
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=buKGkDUg4ouEIGvihpAzCmsgeyjDl8K08J2VqS3ihpXwnZWoKcO3w5fCtDEr4oaV8J2VqH0gbg==">↗️</a><pre> <span class='Value'>k</span> <span class='Brace'>{</span><span class='Paren'>(</span><span class='Function'>×</span><span class='Modifier'>´</span><span class='Value'>𝕩</span><span class='Function'>-↕</span><span class='Value'>𝕨</span><span class='Paren'>)</span><span class='Function'>÷×</span><span class='Modifier'>´</span><span class='Number'>1</span><span class='Function'>+↕</span><span class='Value'>𝕨</span><span class='Brace'>}</span> <span class='Value'>n</span>
10
</pre>
-<p>But we are on the tacit page, so we'd like to make it tacit. For better or for worse. There's a mechanical way to do this for many functions, using only identity functions and trains, and making no simplifications. First parenthesize all monadic functions, as these will become 2-trains. Then replace <code><span class='Value'>𝕨</span></code> and <code><span class='Value'>𝕩</span></code> with <code><span class='Function'>⊣</span></code> and <code><span class='Function'>⊢</span></code>, and add a <code><span class='Modifier'>˙</span></code> to constants. For the number <code><span class='Number'>1</span></code> the added <code><span class='Modifier'>˙</span></code> isn't necessary unless it comes at the end of a train, but we include it here to show the principle.</p>
+<p>But we are on the tacit page, so we'd like to make it tacit. For better or for worse. There's a mechanical way to do this for many functions, using only identity functions and trains, and making no simplifications. First parenthesize all monadic function calls, as these will become 2-trains. Then replace <code><span class='Value'>𝕨</span></code> and <code><span class='Value'>𝕩</span></code> with <code><span class='Function'>⊣</span></code> and <code><span class='Function'>⊢</span></code>, and add a <code><span class='Modifier'>˙</span></code> to constants. For the number <code><span class='Number'>1</span></code> the added <code><span class='Modifier'>˙</span></code> isn't necessary unless it comes at the end of a train, but we include it here to show the principle.</p>
<pre><span class='Brace'>{</span><span class='Paren'>(</span><span class='Function'>×</span><span class='Modifier'>´</span><span class='Value'>𝕩</span><span class='Function'>-↕</span><span class='Value'>𝕨</span><span class='Paren'>)</span><span class='Function'>÷×</span><span class='Modifier'>´</span><span class='Number'>1</span><span class='Function'>+↕</span><span class='Value'>𝕨</span><span class='Brace'>}</span>
<span class='Brace'>{</span><span class='Paren'>(</span><span class='Function'>×</span><span class='Modifier'>´</span><span class='Value'>𝕩</span><span class='Function'>-</span><span class='Paren'>(</span><span class='Function'>↕</span><span class='Value'>𝕨</span><span class='Paren'>))</span><span class='Function'>÷</span><span class='Paren'>(</span><span class='Function'>×</span><span class='Modifier'>´</span><span class='Number'>1</span><span class='Function'>+</span><span class='Paren'>(</span><span class='Function'>↕</span><span class='Value'>𝕨</span><span class='Paren'>))</span><span class='Brace'>}</span> <span class='Comment'># Parenthesize monadic functions