aboutsummaryrefslogtreecommitdiff
path: root/docs/implementation
diff options
context:
space:
mode:
Diffstat (limited to 'docs/implementation')
-rw-r--r--docs/implementation/vm.html1
1 files changed, 1 insertions, 0 deletions
diff --git a/docs/implementation/vm.html b/docs/implementation/vm.html
index 07fd6e95..63fdd9fc 100644
--- a/docs/implementation/vm.html
+++ b/docs/implementation/vm.html
@@ -712,6 +712,7 @@
</tbody>
</table>
<p>To define the final two functions, call the second returned element as a function, with argument <code><span class='Function'>Decompose</span><span class='Ligature'>β€Ώ</span><span class='Function'>PrimInd</span></code>. The function <code><span class='Function'>PrimInd</span></code> gives the index of <code><span class='Value'>𝕩</span></code> in the list of all primitives (defined as <code><span class='Value'>glyphs</span></code> in pr.bqn), or the length of the runtime if <code><span class='Value'>𝕩</span></code> is not a primitive. The two functions are only needed for computing inferred properties, and are defined by default so that every value is assumed to be a primitive, and <code><span class='Function'>PrimInd</span></code> performs a linear search over the returned runtime. If the runtime is used directly, then this means that without setting <code><span class='Function'>Decompose</span><span class='Ligature'>β€Ώ</span><span class='Function'>PrimInd</span></code>, function inferred properties will work slowly and for primitives only; if values from the runtime are wrapped then function inferred properties will not work at all. The compiler uses Under with compound right operands, so <code><span class='Function'>Decompose</span></code> is needed to self-host.</p>
+<p>The compiler returns a third function <code><span class='Function'>SetInv</span></code> as well. This function is used to support inverses of non-primitives like <code><span class='Value'>β€’math.</span><span class='Function'>Sin</span></code> or a block with an Undo header that the runtime has no way to identify. It's not needed for the runtime or compiler. The argument <code><span class='Value'>𝕩</span></code> is a function that takes the runtime's current <code><span class='Function'>Inverse</span></code> function (<code><span class='Modifier'>⁼</span></code> is defined as <code><span class='Brace'>{</span><span class='Value'>i</span><span class='Gets'>←</span><span class='Function'>Inverse</span><span class='Value'>𝕗</span><span class='Separator'>β‹„</span><span class='Value'>𝕨</span><span class='Function'>I</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code>) and returns a new one. If given, <code><span class='Value'>𝕨</span></code> does the same to <code><span class='Function'>SwapInverse</span></code>, the function that inverts <code><span class='Function'>Fn</span><span class='Modifier'>˜</span></code>. The result of <code><span class='Function'>SetInv</span></code> is the new <code><span class='Function'>Inverse</span></code> function.</p>
<p>Remember that <code><span class='Function'>+</span></code> and <code><span class='Function'>-</span></code> can also work on characters in some circumstances, under the rules of affine characters. Other arithmetic functions should only accept numbers. <code><span class='Function'>=</span></code> must work on any atoms including functions and modifiers. <code><span class='Function'>≀</span></code> must work on numbers and characters.</p>
<h3 id="grouplen-and-groupord"><a class="header" href="#grouplen-and-groupord">GroupLen and GroupOrd</a></h3>
<p>GroupLen and GroupOrd, short for Group length and Group order, are used to implement <a href="../doc/group.html">Group</a> (<code><span class='Function'>βŠ”</span></code>) and also to grade small-range lists and invert permutations (the inverse of a permutation <code><span class='Value'>p</span></code> is <code><span class='Number'>1</span><span class='Modifier'>Β¨</span><span class='Modifier2'>⊸</span><span class='Function'>GroupOrd</span> <span class='Value'>p</span></code>). Each of these only needs to work on lists of integers. Shown below are efficient implementations using BQN extended with the notation <code><span class='Paren'>(</span><span class='Value'>i</span><span class='Function'>βŠ‘</span><span class='Value'>l</span><span class='Paren'>)</span> <span class='Function'>Fn</span><span class='Gets'>↩</span> <span class='Value'>x</span></code> meaning <code><span class='Value'>l</span> <span class='Gets'>↩</span> <span class='Function'>Fn</span><span class='Modifier2'>⟜</span><span class='Value'>x</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Value'>i</span><span class='Modifier2'>⊸</span><span class='Function'>βŠ‘</span><span class='Paren'>)</span> <span class='Value'>l</span></code>, where <code><span class='Function'>Fn</span></code> is <code><span class='Function'>⊒</span></code> if omitted. Since these special assignments only change one element of <code><span class='Value'>l</span></code>, each can be a fast constant-time operation.</p>