aboutsummaryrefslogtreecommitdiff
path: root/docs/doc/shape.html
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-06-12 21:35:20 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-06-12 21:39:52 -0400
commitfb9b75b9f6014f81e8e944f8b105ec75d9ecdc0d (patch)
tree0b2bc41ae55c4c70be293e34db2b1889f8e393bd /docs/doc/shape.html
parentd030b119ca512e0b0f3b44554ac96ce3eeb2350e (diff)
Use Enclose documentation as an excuse to talk about unit arrays
Diffstat (limited to 'docs/doc/shape.html')
-rw-r--r--docs/doc/shape.html2
1 files changed, 1 insertions, 1 deletions
diff --git a/docs/doc/shape.html b/docs/doc/shape.html
index 350e3587..5852a698 100644
--- a/docs/doc/shape.html
+++ b/docs/doc/shape.html
@@ -45,7 +45,7 @@
⟨ 0 1 ⟩
</pre>
<h2 id="units">Units</h2>
-<p>A unit is an atom, or an array with no axes—rank 0. Since it doesn't have any axes, its shape should have no elements. It should be the empty list <code><span class='Bracket'>⟨⟩</span></code> (with a fill of <code><span class='Number'>0</span></code>, like all shapes). As there's no first element in the shape, it's not obvious what the length should be, and a stricter language would just give an error. However, there are some good reasons to use a length of <code><span class='Number'>1</span></code>. First, the total number of elements is 1, meaning that if the length divides this number evenly (as it does for non-unit arrays) then the only possible natural number it can be is 1. Second, many functions that take a list for a particular argument also accept a unit, and treat it as a length-1 array. For example, <code><span class='Number'>5</span><span class='Function'>⥊</span><span class='Value'>a</span></code> and <code><span class='Bracket'>⟨</span><span class='Number'>5</span><span class='Bracket'>⟩</span><span class='Function'>⥊</span><span class='Value'>a</span></code> are identical. Defining <code><span class='Function'>≠</span><span class='Number'>5</span></code> to be <code><span class='Number'>1</span></code> means that <code><span class='Function'>=</span><span class='Value'>s</span><span class='Function'>⥊</span><span class='Value'>a</span></code> is always <code><span class='Function'>≠</span><span class='Value'>s</span></code>.</p>
+<p>A unit is an atom, or an array with no axes—rank 0. (See <a href="enclose.html">Enclose</a> for more about unit arrays). Since it doesn't have any axes, its shape should have no elements. It should be the empty list <code><span class='Bracket'>⟨⟩</span></code> (with a fill of <code><span class='Number'>0</span></code>, like all shapes). As there's no first element in the shape, it's not obvious what the length should be, and a stricter language would just give an error. However, there are some good reasons to use a length of <code><span class='Number'>1</span></code>. First, the total number of elements is 1, meaning that if the length divides this number evenly (as it does for non-unit arrays) then the only possible natural number it can be is 1. Second, many functions that take a list for a particular argument also accept a unit, and treat it as a length-1 array. For example, <code><span class='Number'>5</span><span class='Function'>⥊</span><span class='Value'>a</span></code> and <code><span class='Bracket'>⟨</span><span class='Number'>5</span><span class='Bracket'>⟩</span><span class='Function'>⥊</span><span class='Value'>a</span></code> are identical. Defining <code><span class='Function'>≠</span><span class='Number'>5</span></code> to be <code><span class='Number'>1</span></code> means that <code><span class='Function'>=</span><span class='Value'>s</span><span class='Function'>⥊</span><span class='Value'>a</span></code> is always <code><span class='Function'>≠</span><span class='Value'>s</span></code>.</p>
<p>Despite this last point, it's important to remember that a unit isn't the same as a 1-element list. For example, the length-1 string <code><span class='String'>&quot;a&quot;</span></code> doesn't match <code><span class='Function'>&lt;</span><span class='String'>'a'</span></code> but instead <code><span class='Bracket'>⟨</span><span class='String'>'a'</span><span class='Bracket'>⟩</span></code>. And also bear in mind that having an empty <em>shape</em> doesn't make a unit an empty <em>array</em>. That would mean it has no elements, not one!</p>
<table>
<thead>