aboutsummaryrefslogtreecommitdiff
path: root/docs/commentary/overload.html
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2022-09-12 21:34:06 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2022-09-12 21:34:06 -0400
commit4c6e15275efbc976ff72cbfd7db74756d8afa25f (patch)
tree80740be2c1350c657e6966b69feaaccbc29b5a05 /docs/commentary/overload.html
parentbc968cf2a3c7b5aecba24a05b073b2d2de9db3ec (diff)
Editing
Diffstat (limited to 'docs/commentary/overload.html')
-rw-r--r--docs/commentary/overload.html4
1 files changed, 2 insertions, 2 deletions
diff --git a/docs/commentary/overload.html b/docs/commentary/overload.html
index b5ab0f3e..f6bfaa68 100644
--- a/docs/commentary/overload.html
+++ b/docs/commentary/overload.html
@@ -25,7 +25,7 @@
<p>Heading further into the woods, we see that the APL family extends functions in ways that don't follow strictly from the definition. Usually this happens within a single primitive. For example, First (monadic <code><span class='Function'>⊑</span></code>) is only natural to apply to an array, since otherwise there's no first element. But it's defined to return an atom with no changes, effectively treating it as a unit array. This sort of implicit promotion is used just about everywhere it could be, since in all cases it's obvious what needs to be done and inconvenient to require explicit conversion.</p>
<p>If that was all, it would hardly be worth mentioning. A more significant family of extensions is the <a href="../doc/depth.html#testing-depth-for-multiple-axis-primitives">use of depth</a> to allow a primitive to work on multiple axes in general but also to have a convenient one-axis form. Then there's <a href="../doc/arithmetic.html#character-arithmetic">character arithmetic</a>, allowing <code><span class='String'>'a'</span> <span class='Function'>+</span> <span class='Number'>3</span></code>. In fact, isn't array arithmetic itself a big extension?</p>
<p>There are examples outside the array world that I find worse than anything in BQN. <code><span class='Function'>+</span></code> for string catenation. This no longer obeys commutativity or distributivity: it's not safe to rearrange <code><span class='Value'>a</span> <span class='Function'>+</span> <span class='Value'>b</span></code> to <code><span class='Value'>b</span> <span class='Function'>+</span> <span class='Value'>a</span></code> or <code><span class='Paren'>(</span><span class='Value'>a</span><span class='Function'>+</span><span class='Value'>b</span><span class='Paren'>)</span><span class='Value'>*c</span></code> to <code><span class='Paren'>(</span><span class='Value'>a*c</span><span class='Paren'>)</span><span class='Function'>+</span><span class='Paren'>(</span><span class='Value'>b*c</span><span class='Paren'>)</span></code> in languages that do this! NumPy and MATLAB allow a boolean array to be used as an index, performing filtering. This one doesn't obey the rule that the length of <code><span class='Value'>a</span><span class='Bracket'>[</span><span class='Value'>b</span><span class='Bracket'>]</span></code> is the length of <code><span class='Value'>b</span></code>, or any other length-based rules really.</p>
-<p>Sometimes what seems like an extension can be unified into a single more general primitive. For example, APL has <a href="https://aplwiki.com/wiki/Scalar_extension">scalar extension</a> to allow you to add, say, a scalar to a list in <code><span class='Number'>1</span> <span class='Function'>+</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span></code>. J and BQN use the more general <a href="../doc/leading.html#leading-axis-agreement">leading axis agreement</a>, which has this extension as a special case (although incidentally, BQN removes some unprincipled extension of list-like functions like Reverse to rank-0 arguments). Character arithmetic can also be viewed in this way considering numbers and characters to be pairs of &quot;characterness&quot; 0 or 1, and a numeric value.</p>
+<p>Sometimes what seems like an extension can be unified into a single more general primitive. For example, APL has <a href="https://aplwiki.com/wiki/Scalar_extension">scalar extension</a> to allow you to add, say, a scalar to a list in <code><span class='Number'>1</span> <span class='Function'>+</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span></code>. J and BQN use the more general <a href="../doc/leading.html#leading-axis-agreement">leading axis agreement</a>, which has this extension as a special case (although incidentally, BQN removes some unprincipled extension of list-like functions like Reverse to rank-0 arguments). Character arithmetic can also be viewed in this way, by considering numbers and characters to be pairs of &quot;characterness&quot; 0 or 1, and a numeric value.</p>
<p>I think many primitive pairs, such as <code><span class='Function'>-</span></code>, <code><span class='Function'>⋆</span></code>, <code><span class='Function'>«</span></code>, <code><span class='Function'>⥊</span></code>, and <code><span class='Function'>⍉</span></code>, fall into this category too. These can all be described as a general dyadic function, and a monadic case that comes from a default left argument (sometimes dependent on the right argument: it's <code><span class='Paren'>(</span><span class='Function'>=</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>-</span><span class='Number'>1</span></code> for <code><span class='Function'>⍉</span></code>). The primitive <code><span class='Function'>⋈</span></code> is so tight it might be considered a fully compatible overload, returning a list of all arguments. Such primitive pairs can sometimes be used ambivalently in simple ways (<code><span class='Function'>⋆</span><span class='Modifier'>⁼</span></code> is pretty nice), but more often the usefulness is just that it's easier to think about each pair as one thing rather than two. It's just two views of the same idea.</p>
<h2 id="mnemonic-overloading"><a class="header" href="#mnemonic-overloading">Mnemonic overloading</a></h2>
<p>Okay, we are slipping down the slope nicely, now what about the primitives where the two halves don't quite do the same thing? Take <code><span class='Function'>∾</span></code> to start smoothly. The dyadic form joins two lists and the monadic form joins a list of lists. Well, this is really one function that takes its arguments in a slightly unusual way, since dyadic <code><span class='Function'>∾</span></code> is <code><span class='Function'>∾</span><span class='Modifier2'>∘</span><span class='Function'>⋈</span></code>. The primitive <code><span class='Function'>↑</span></code> for Prefixes/Take (<code><span class='Function'>↓</span></code> too) is similar, but in a trickier way: if <code><span class='Value'>𝕨</span></code> is between <code><span class='Number'>0</span></code> and <code><span class='Function'>≠</span><span class='Value'>𝕩</span></code>, <code><span class='Value'>𝕨</span><span class='Function'>↑</span><span class='Value'>𝕩</span></code> is a prefix of <code><span class='Value'>𝕩</span></code>. Then <code><span class='Function'>↑</span></code> is the list of all these prefixes, so <code><span class='Value'>𝕨</span><span class='Function'>⊑↑</span><span class='Value'>𝕩</span></code> is <code><span class='Value'>𝕨</span><span class='Function'>↑</span><span class='Value'>𝕩</span></code>. It's almost a kind of partial application.</p>
@@ -33,7 +33,7 @@
<p>In <code><span class='Function'>/</span></code> and <code><span class='Function'>⊔</span></code>, the monadic case is like the dyadic one but using indices (with the <a href="problems.html#monadic-argument-corresponds-to-left-for--and-">minor issue</a> that <code><span class='Value'>𝕨</span></code> swaps over to <code><span class='Value'>𝕩</span></code>). Either form can be implemented in terms of the other. I still think of each of these primitives as a single concept, instead of two closely related ones.</p>
<p>And then we reach the cases that I think of as purely mnemonic, in that they the two cases are closely related, and it's useful to know this when programming, but neither one can be written in terms of the other. <a href="../doc/order.html">Both meanings</a> of <code><span class='Function'>⍋</span></code> use array ordering, and the connections between them run pretty deep (that might require another article to explore properly). A weaker example is <code><span class='Function'>⌊</span></code>, which in both cases returns the greatest value smaller than or equal to any argument, but restricts the result to be an integer in the monadic case.</p>
<p>The examples are all primitive pairs now, and that's because BQN doesn't use mnemonic overloading within primitives (APL does occasionally, such as <code><span class='Modifier2'>○</span></code>, and J has a number of kitchen-sink primitives like <code><span class='Head'>;</span><span class='Value'>.</span></code> and <code><span class='Value'>p</span><span class='Head'>:</span></code>). And of course, there's a level after this where there's just no connection. BQN glyphs aren't chosen randomly, so the reason that this happens is that both functions are separately a fit for the glyph. But as I said at the beginning, in a language not tied to primitive glyphs there's no reason to do this.</p>
-<p>Here's my list of how the primitives fit together. The table fits into rows, but there are no hard distinctions; I've tried to put the more coherent pairs of functions closer the the beginning of each row.</p>
+<p>Here's my list of how the primitives fit together. The table fits into rows, but there are no hard distinctions; I've tried to put the more coherent pairs of functions closer to the beginning of each row.</p>
<table>
<thead>
<tr>