aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-10-04 20:18:48 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-10-04 20:19:27 -0400
commit18c0dac23140426089fdb060042533a523a045f9 (patch)
tree7b73f4c82a9c403655e69705a16b88dfc7deeec9
parent2b4c0501f9c0bf3275b907eedf54b574adbc3e97 (diff)
Diagram of types and the categories they use
-rw-r--r--doc/types.md30
-rw-r--r--docs/doc/types.html23
-rw-r--r--docs/style.css9
-rw-r--r--svg.bqn38
4 files changed, 99 insertions, 1 deletions
diff --git a/doc/types.md b/doc/types.md
index ed8141a1..feef755e 100644
--- a/doc/types.md
+++ b/doc/types.md
@@ -13,6 +13,36 @@ BQN supports the following fundamental types:
The first three types are called *data types*, and the rest are *operation types*. The array is the only *compound type*; the other types are *atomic types* and values of these types are called *atoms*. The fact that an array is only one type of many is common in modern programming languages but a novelty in the APL family. This decision is discussed in the page on [based array theory](based.md).
+<!--SVG
+types ← ⍉"Number"‿"Character"‿"Array"≍"Function"‿"1-modifier"‿"2-modifier"
+sh ← ≢ types
+p ← 64‿38
+dim ← (2×p) + sh × d1 ← 128‿64
+rp ← 8÷d1
+Pos ↩ Pos d1⊸×
+Size ← "width"‿"height" ≍˘ ·FmtNum¨ d1×⊢
+cl ← {"class"‿𝕩}¨ "purple"‿"bluegreen"‿"yellow"
+
+TP ← "text" Attr "dy"‿"0.32em"∾˜Pos⊘(∾⟜Pos)
+t ← (≍⌜´0.5+↕¨sh) TP⊸Enc¨ types
+l ← (cl TP¨ (0.75≍¨1(-≍+)1.2)∾<2.2‿2.3) Enc¨ "Data"‿"Operation"‿"Atom"
+RD← (Size ⟨⊑sh,1⟩-2×rp)∾Pos
+r ← (2↑cl) {"rect" Elt 𝕩∾"rx"‿"10px"≍𝕨}⟜RD¨ 0(rp+≍)¨↕1⊑sh
+
+Round ← {
+ v ← (𝕨⊸×÷+´⌾(ט))¨ ¯1⊸⌽⊸- 𝕩
+ or← 0< v +´∘×⟜(⌽-⌾⊑)¨ 1⌽v
+ "Z"∾˜ 'M'⌾⊑ ∾ ⥊ (('L'∾Fmt)¨ v+𝕩) ≍˘ or ('A'∾·Fmt(𝕨‿𝕨∾0‿0)∾∾)¨ (1⌽-v)+𝕩
+}
+a ← "path" Elt >⟨"d"‿(12 Round d1⊸ר ⥊ ((⊢≍˘1⊸⌽) 0‿2‿3) ≍¨ ↕3),¯1⊑cl⟩
+
+FS ← {𝕩 Enc˜ "g"Attr⟨"font-size",(Fmt𝕨)∾"px"⟩}
+((0‿2-p)∾dim) SVG ⟨
+ "g stroke-width='2'" Enc a‿r
+ "g text-anchor='middle' fill='currentColor'" Enc 18‿16 FS¨ t‿l
+⟩
+-->
+
All of these types are immutable, meaning that a particular copy of a value will never change (to go further, with immutable types it doesn't really make sense to talk about a "copy" of a value: values just exist and nothing you do will affect them). The only form of mutability BQN has is the ability to change the value of a particular variable, that is, make the variable refer to a different value. Such a change can also change the behavior of a function or modifier that has the variable in its scope, and in this sense operation types are mutable—in fact it is possible to implement typical mutable data structures as functions that act on enclosed state.
It is likely that in the future [namespaces](extensions.md#namespaces-and-symbols), or references to enclosed scopes, will be added as a more directly manipulable mutable data type.
diff --git a/docs/doc/types.html b/docs/doc/types.html
index 373fc10f..c2ae74e5 100644
--- a/docs/doc/types.html
+++ b/docs/doc/types.html
@@ -15,6 +15,29 @@
<li>2-<a href="#modifiers">Modifier</a></li>
</ul>
<p>The first three types are called <em>data types</em>, and the rest are <em>operation types</em>. The array is the only <em>compound type</em>; the other types are <em>atomic types</em> and values of these types are called <em>atoms</em>. The fact that an array is only one type of many is common in modern programming languages but a novelty in the APL family. This decision is discussed in the page on <a href="based.html">based array theory</a>.</p>
+<svg viewBox='-64 -36 512 204'>
+ <g stroke-width='2'>
+ <path d='M0 12A12 12 0 0 1 12 0L244 0A12 12 0 0 1 256 12L256 52A12 12 0 0 0 268 64L372 64A12 12 0 0 1 384 76L384 116A12 12 0 0 1 372 128L12 128A12 12 0 0 1 0 116Z' class='yellow'/>
+ <rect width='368' height='48' x='8' y='8' rx='10px' class='purple'/>
+ <rect width='368' height='48' x='8' y='72' rx='10px' class='bluegreen'/>
+ </g>
+ <g text-anchor='middle' fill='currentColor'>
+ <g font-size='18px'>
+ <text x='64' y='32' dy='0.32em'>Number</text>
+ <text x='64' y='96' dy='0.32em'>Function</text>
+ <text x='192' y='32' dy='0.32em'>Character</text>
+ <text x='192' y='96' dy='0.32em'>1-modifier</text>
+ <text x='320' y='32' dy='0.32em'>Array</text>
+ <text x='320' y='96' dy='0.32em'>2-modifier</text>
+ </g>
+ <g font-size='16px'>
+ <text class='purple' x='96' y='-12.8' dy='0.32em'>Data</text>
+ <text class='bluegreen' x='96' y='140.8' dy='0.32em'>Operation</text>
+ <text class='yellow' x='281.6' y='147.2' dy='0.32em'>Atom</text>
+ </g>
+ </g>
+</svg>
+
<p>All of these types are immutable, meaning that a particular copy of a value will never change (to go further, with immutable types it doesn't really make sense to talk about a &quot;copy&quot; of a value: values just exist and nothing you do will affect them). The only form of mutability BQN has is the ability to change the value of a particular variable, that is, make the variable refer to a different value. Such a change can also change the behavior of a function or modifier that has the variable in its scope, and in this sense operation types are mutable—in fact it is possible to implement typical mutable data structures as functions that act on enclosed state.</p>
<p>It is likely that in the future <a href="extensions.html#namespaces-and-symbols">namespaces</a>, or references to enclosed scopes, will be added as a more directly manipulable mutable data type.</p>
<h2 id="data-types">Data types</h2>
diff --git a/docs/style.css b/docs/style.css
index 0a8727c9..1f1e9fa0 100644
--- a/docs/style.css
+++ b/docs/style.css
@@ -143,3 +143,12 @@ a:visited { color: #3d155f; }
a:link { color: #5592d9; text-decoration-color: #508dd978; }
a:visited { color: #8781c1; }
}
+
+.purple { fill:#d6afe0; stroke:#3d1b46; } text.purple { fill:#3b1346; stroke:none; }
+.bluegreen { fill:#55cbcb; stroke:#1c4e4e; } text.bluegreen { fill:#113939; stroke:none; }
+.yellow { fill:#e2d17f; stroke:#a28237; } text.yellow { fill:#7a5a0e; stroke:none; }
+@media (prefers-color-scheme: dark) {
+.purple { fill:#241922; stroke:#612d86; } text.purple { fill:#6e2ca0; stroke:none; }
+.bluegreen { fill:#0e2525; stroke:#297f7f; } text.bluegreen { fill:#578d8d; stroke:none; }
+.yellow { fill:#5b4b25; stroke:#a27e2a; } text.yellow { fill:#9d7925; stroke:none; }
+}
diff --git a/svg.bqn b/svg.bqn
index 728cc76e..69441d66 100644
--- a/svg.bqn
+++ b/svg.bqn
@@ -1,2 +1,38 @@
# Utilities for creating SVG diagrams as strings
-# (There aren't any yet; go to the next commit)
+
+IsLines ← 1<≡
+DeNest ← {(3⌊≡)◶⟨!∘0,⥊<,⊢,∾𝕊¨⟩ ⥊𝕩}
+Indent ← " "⊸∾¨ DeNest
+
+# Create a node from a tag name and interior text.
+Enc ← {
+ open ← ∾⟨"<",𝕨,">"⟩
+ close← ∾⟨"</", (⊑𝕨⊐" ")↑𝕨, ">"⟩
+ l ← IsLines 𝕩
+ ∾ open (Indent⍟l 𝕩){𝕨‿𝕗‿𝕩}○(⥊∘<⍟l) close
+}
+Void ← {∾⟨"<",𝕩,"/>"⟩}
+
+FmtNum ← {
+ ! 0=≡𝕩
+ ! (¯∞⊸< ∧ <⟜∞) 𝕩
+ d ← 3 ⋆˜ b←10 # Base 10, up to 3 decimals
+ _base ← {⌽b|⌊∘÷⟜b⍟(↕𝔽)} # 𝔽 is the number of digits
+ fl ← ⌊ abs ← (÷2×d) + |𝕩
+ ∾ ⟨
+ (𝕩<0) / "-"
+ '0' + (1+·⌊b⋆⁼1⌈⊢)_base fl
+ 0⊸<◶""‿("." ∾ '0' + · ∨`⌾⌽∘×⊸/ 3 _base) ⌊ d × abs-fl
+ ⟩
+}
+Fmt ← (2⌊≡)◶FmtNum‿(1↓·∾(' '∾FmtNum)¨)‿{𝕩⋄!0}
+
+Attr ← {
+ 𝕨 ∾ ∾ {<∾⟨" ",𝕨,"='",𝕩,"'"⟩}´⎉1 𝕩
+}
+Pos ← ⟨"x","y"⟩ ≍˘ FmtNum¨
+Elt ← Void∘Attr
+
+SVG ← {
+ (∾∾⟜(10+@)¨)⍟IsLines ("svg" Attr ⟨"viewBox",Fmt 𝕨⟩) Enc 𝕩
+}