From 4c6e15275efbc976ff72cbfd7db74756d8afa25f Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 12 Sep 2022 21:34:06 -0400 Subject: Editing --- docs/commentary/overload.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/commentary/overload.html') 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 @@

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 ) 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.

If that was all, it would hardly be worth mentioning. A more significant family of extensions is the use of depth to allow a primitive to work on multiple axes in general but also to have a convenient one-axis form. Then there's character arithmetic, allowing 'a' + 3. In fact, isn't array arithmetic itself a big extension?

There are examples outside the array world that I find worse than anything in BQN. + for string catenation. This no longer obeys commutativity or distributivity: it's not safe to rearrange a + b to b + a or (a+b)*c to (a*c)+(b*c) 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 a[b] is the length of b, or any other length-based rules really.

-

Sometimes what seems like an extension can be unified into a single more general primitive. For example, APL has scalar extension to allow you to add, say, a scalar to a list in 1 + 234. J and BQN use the more general leading axis agreement, 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 "characterness" 0 or 1, and a numeric value.

+

Sometimes what seems like an extension can be unified into a single more general primitive. For example, APL has scalar extension to allow you to add, say, a scalar to a list in 1 + 234. J and BQN use the more general leading axis agreement, 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 "characterness" 0 or 1, and a numeric value.

I think many primitive pairs, such as -, , «, , and , 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 (=𝕩)-1 for ). The primitive 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 ( 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.

Mnemonic overloading

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 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 is . The primitive for Prefixes/Take ( too) is similar, but in a trickier way: if 𝕨 is between 0 and 𝕩, 𝕨𝕩 is a prefix of 𝕩. Then is the list of all these prefixes, so 𝕨⊑↑𝕩 is 𝕨𝕩. It's almost a kind of partial application.

@@ -33,7 +33,7 @@

In / and , the monadic case is like the dyadic one but using indices (with the minor issue that 𝕨 swaps over to 𝕩). 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.

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. Both meanings of use array ordering, and the connections between them run pretty deep (that might require another article to explore properly). A weaker example is , 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.

The examples are all primitive pairs now, and that's because BQN doesn't use mnemonic overloading within primitives (APL does occasionally, such as , and J has a number of kitchen-sink primitives like ;. and p:). 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.

-

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.

+

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.

-- cgit v1.2.3