From 2afb23928e1984d475cc460e1672e8f6fa0e4dbe Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 11 Aug 2021 17:21:31 -0400 Subject: Allow clicking on header to get fragment link --- docs/doc/enclose.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/doc/enclose.html') diff --git a/docs/doc/enclose.html b/docs/doc/enclose.html index 2be9bddb..aac48d68 100644 --- a/docs/doc/enclose.html +++ b/docs/doc/enclose.html @@ -4,7 +4,7 @@ BQN: Enclose -

Enclose

+

Enclose

The function enclose creates a unit array whose only element is 𝕩.

↗️
    < "xyz"
 ┌·       
@@ -13,7 +13,7 @@
 

If you understand the concept of a unit array, then that definition almost certainly made sense to you. Therefore the remainder of this document will explain what a unit array is, what it isn't, and why you would use it.

If you're familiar with the Enclose or Box function from APL or J (but particularly APL), then it's possible you understand the concept of a unit array wrongly, or at least, not in the same way BQN uses it. A difference from APL is that <𝕩 is never the same as 𝕩. I recommend reading about based array theory if you haven't already.

-

What's a unit?

+

What's a unit?

A unit array is an array with no axes: that is, it has rank 0 and its shape is the empty list. The array itself isn't empty though. The number of elements is the product of the shape, which is 1.

↗️
        <"anything"   # empty shape
 ⟨⟩
@@ -45,9 +45,9 @@ ERROR
 

The function +´˘ tries to mix together the result elements into one big array, causing an error because they have different lengths, but +˝˘ keeps them as elements.

One strained example probably isn't all that compelling. And it doesn't explain why you'd use Enclose, which doesn't remove an axis from an existing array but creates a whole new unit array. So…

-

Why create a unit?

+

Why create a unit?

Why indeed?

-

Table of combinations

+

Table of combinations

Let's take a look at the following program, which uses Table () to create an array of combinations—every possibility from three sets of choices. It uses Enclose not once but twice.

↗️
    (<⟨⟩) <⌜´ """anti", "red""blue""green", "up""down"
 ┌─                                                   
@@ -112,7 +112,7 @@ ERROR
   ⟨ "green" "down" "quark" ⟩ ⟨ "green" "strange" "quark" ⟩ ⟨ "green" "bottom" "quark" ⟩  
                                                                                         ┘
 
-

Broadcasting

+

Broadcasting

Table isn't the only mapping function that gets along well with units. Here's an example with Each (¨).

↗️
    = {𝕎𝕩}¨ < 32"abcdef"
 ⟨ 2 3 1 ⟨ 3 2 ⟩ ⟩
@@ -125,7 +125,7 @@ ERROR
   ⟨ 14 ¯9 ⟩ ⟨ 15 ¯6 ⟩  
                       ┘
 
-

Coda

+

Coda

Perhaps you feel bludgeoned rather than convinced at this point. Unit arrays are useful, sure, but aren't they ugly? Aren't they a hack?

The practical answer is that I think you should use them anyway. You'll probably come to appreciate the use of Enclose and how it can help you produce working, reliable code, making you a more effective BQN programmer.

On the theoretical side, it's important to realize that units are just a consequence of having multidimensional arrays. Array languages come with units be default, so that "adding" them is not really a complication, it's a simplification. It's natural to not feel quite right around these sorts of non-things, because zero is a pretty special number—being among other things the only number of paddles you can have and still not be able to go anywhere in your canoe. In my opinion the right response is to understand why they are special but also why they fit in as part of the system, so you can be in control instead of worrying.

-- cgit v1.2.3