aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-06-16 22:49:51 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-06-16 22:52:58 -0400
commit3cb0260e07d5db98a415e55efaa276ee38620e0f (patch)
tree84c76e7568fc95999417bfb2461369eb2ab92d0f
parent08ad1e1bb0a30c6bb4164f5665aa4d0f7f158742 (diff)
Depth diagram
-rw-r--r--doc/depth.md29
-rw-r--r--docs/doc/depth.html47
2 files changed, 76 insertions, 0 deletions
diff --git a/doc/depth.md b/doc/depth.md
index f2dfe34a..23bfe37b 100644
--- a/doc/depth.md
+++ b/doc/depth.md
@@ -2,6 +2,35 @@
# Depth
+<!--GEN
+d ← 48‿40
+a ← ⟨⟨@,⟨@,@,@⟩⟩,@,⟨@,@⟩⟩
+
+g ← "g"At"font-family=BQN,monospace|font-size=16px|text-anchor=middle|fill=currentColor|stroke-width=0|stroke=currentColor|stroke-linecap=round"
+rc ← At "class=code|stroke-width=1.5|rx=12"
+lc ← "line"At"stroke-width=2|class=purple|opacity=0.8"
+tc ← "text"At"dy=-0.2em|class=Number"
+
+TN←tc Enc FmtNum
+TL←lc Elt"x2"‿"y2"≍˘·FmtNum 0‿18-˜d×≍⟜1
+GTr←{("g"Attr⟨"transform","translate("∾(Fmt d×𝕨)∾")"⟩) Enc 𝕩}
+Tree←{
+ ds‿ws‿e←<˘⍉>𝕩
+ d←1+0⌈´ds
+ ww←1⌈+´ws
+ p←2÷˜(-ww)+`»⊸+ws
+ ⟨d,ww,⟨TN d⟩∾(TL¨p)∾∾p≍⟜1⊸Gtr¨e⟩
+}
+dp‿wd‿tr ← {@⊸≢◶⟨0‿1‿⟨TN 0⟩, Tree𝕊¨⟩𝕩} a
+
+dim ← ⟨1+wd,1.3+dp⟩ ⋄ sh ← ⟨-2÷˜⊑dim,¯0.8⟩
+
+((∾˜d)×((-∾+˜)1.8‿0.4)+sh∾dim) SVG g Enc ⟨
+ "rect" Elt rc∾(Pos d×sh) ∾ "width"‿"height"≍˘FmtNum d×dim
+ tr
+⟩
+-->
+
The depth of an array is the greatest level of array nesting it attains, or, put another way, the greatest number of times you can pick an element starting from the original array before reaching an atom. The monadic function Depth (`≡`) returns the depth of its argument, while the 2-modifier Depth (`⚇`) can control the way its left operand is applied based on the depth of its arguments. Several primitive functions also use the depth of the left argument to decide whether it applies to a single axis of the right argument or to several axes.
## The Depth function
diff --git a/docs/doc/depth.html b/docs/doc/depth.html
index dcb4f812..2b975c4e 100644
--- a/docs/doc/depth.html
+++ b/docs/doc/depth.html
@@ -5,6 +5,53 @@
</head>
<div class="nav"><a href="https://github.com/mlochbaum/BQN">BQN</a> / <a href="../index.html">main</a> / <a href="index.html">doc</a></div>
<h1 id="depth">Depth</h1>
+<svg viewBox='-278.4 -48 556.8 204'>
+ <g font-family='BQN,monospace' font-size='16px' text-anchor='middle' fill='currentColor' stroke-width='0' stroke='currentColor' stroke-linecap='round'>
+ <rect class='code' stroke-width='1.5' rx='12' x='-192' y='-32' width='384' height='172'/>
+ <text dy='-0.2em' class='Number'>3</text>
+ <line stroke-width='2' class='purple' opacity='0.8' x2='-72' y2='22'/>
+ <line stroke-width='2' class='purple' opacity='0.8' x2='48' y2='22'/>
+ <line stroke-width='2' class='purple' opacity='0.8' x2='120' y2='22'/>
+ <g transform='translate(-72 40)'>
+ <text dy='-0.2em' class='Number'>2</text>
+ <line stroke-width='2' class='purple' opacity='0.8' x2='-72' y2='22'/>
+ <line stroke-width='2' class='purple' opacity='0.8' x2='24' y2='22'/>
+ <g transform='translate(-72 40)'>
+ <text dy='-0.2em' class='Number'>0</text>
+ </g>
+ <g transform='translate(24 40)'>
+ <text dy='-0.2em' class='Number'>1</text>
+ <line stroke-width='2' class='purple' opacity='0.8' x2='-48' y2='22'/>
+ <line stroke-width='2' class='purple' opacity='0.8' x2='0' y2='22'/>
+ <line stroke-width='2' class='purple' opacity='0.8' x2='48' y2='22'/>
+ <g transform='translate(-48 40)'>
+ <text dy='-0.2em' class='Number'>0</text>
+ </g>
+ <g transform='translate(0 40)'>
+ <text dy='-0.2em' class='Number'>0</text>
+ </g>
+ <g transform='translate(48 40)'>
+ <text dy='-0.2em' class='Number'>0</text>
+ </g>
+ </g>
+ </g>
+ <g transform='translate(48 40)'>
+ <text dy='-0.2em' class='Number'>0</text>
+ </g>
+ <g transform='translate(120 40)'>
+ <text dy='-0.2em' class='Number'>1</text>
+ <line stroke-width='2' class='purple' opacity='0.8' x2='-24' y2='22'/>
+ <line stroke-width='2' class='purple' opacity='0.8' x2='24' y2='22'/>
+ <g transform='translate(-24 40)'>
+ <text dy='-0.2em' class='Number'>0</text>
+ </g>
+ <g transform='translate(24 40)'>
+ <text dy='-0.2em' class='Number'>0</text>
+ </g>
+ </g>
+ </g>
+</svg>
+
<p>The depth of an array is the greatest level of array nesting it attains, or, put another way, the greatest number of times you can pick an element starting from the original array before reaching an atom. The monadic function Depth (<code><span class='Function'>≡</span></code>) returns the depth of its argument, while the 2-modifier Depth (<code><span class='Modifier2'>⚇</span></code>) can control the way its left operand is applied based on the depth of its arguments. Several primitive functions also use the depth of the left argument to decide whether it applies to a single axis of the right argument or to several axes.</p>
<h2 id="the-depth-function">The Depth function</h2>
<p>To find the depth of an array, use Depth (<code><span class='Function'>≡</span></code>). For example, the depth of a list of numbers or characters is 1:</p>