diff options
| -rw-r--r-- | doc/types.md | 31 | ||||
| -rw-r--r-- | docs/doc/types.html | 38 |
2 files changed, 40 insertions, 29 deletions
diff --git a/doc/types.md b/doc/types.md index a78dbdb4..3e37ffed 100644 --- a/doc/types.md +++ b/doc/types.md @@ -10,31 +10,32 @@ BQN supports the following fundamental types: - [Function](#functions) - 1-[Modifier](#modifiers) - 2-[Modifier](#modifiers) +- [Namespace](#namespaces) -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). +The first three types, called *data types*, are immutable; the others are mutable. Functions and modifiers together are the *operation types*. Types other than the array 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). <!--GEN -types ← ⍉"Number"‿"Character"‿"Array"≍"Function"‿"1-modifier"‿"2-modifier" -sh ← ≢ types +types ← ⟨"Number"‿"Character"‿"Array","Function"‿"1-modifier"‿"2-modifier"‿"Namespace"⟩ +sh ← 4‿2 p ← 64‿38 -dim ← (2×p) + sh × d1 ← 128‿64 +dim ← (2×p) + sh × d1 ← 128‿68 rp ← 8÷d1 Pos ↩ Pos d1⊸× Size ← "width"‿"height" ≍˘ ·FmtNum d1×⊢ -cl ← {"class"‿𝕩}¨ "purple"‿"bluegreen"‿"yellow" +cl ← {"class"‿𝕩}¨ "purple"‿"green"‿"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 +TP ← "text" Attr "dy"‿"0.35em"∾˜Pos⊘(∾⟜Pos) +t ← ∾(0.5+↕2) (TP∘≍˜¨⟜((4÷≠)×0.5+↕∘≠)Enc¨⊢)¨ types +l ← (cl TP¨ ⟨2.75‿¯0.15,3‿2.2,1.5‿2.2,1.1‿¯0.3⟩) Enc¨ "Data"‿"Mutable"‿"Operation"‿"Atom" +rd← (÷⟜2⌾(⊑¯1⊸⊑)2‿1.5‿3×<(¯1≍÷2)×⌜rp) + (4‿4‿3≍¨1) ≍¨ 1‿2/0≍¨↕2 +r ← (3↑cl) ("rect" Elt ∾˜)¨ (FmtNum 9‿10‿8) {𝕩∾⟨"rx",𝕨∾"px"⟩}¨ Size⊸∾⟜Pos˝¨ rd 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⟩ +a ← "path" Elt >⟨"d"‿(12 Round d1⊸ר ⥊ ((⊢≍˘1⊸⌽) 0‿2.6‿4) ≍¨ ↕3),¯1⊑cl⟩ FS ← {𝕩 Enc˜ "g"Attr⟨"font-size",(Fmt𝕨)∾"px"⟩} ((0‿2-p)∾dim) SVG ⟨ @@ -43,9 +44,9 @@ FS ← {𝕩 Enc˜ "g"Attr⟨"font-size",(Fmt𝕨)∾"px"⟩} ⟩ --> -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. +The reason operations and namespaces are called "mutable" is that the values obtained from them—by calling an operation on particular arguments or reading a field from a namespace—may change over the course of the program. This property is caused by variable modification `↩`, which can directly change a namespace field, or change the behavior of an operation that uses the modified variable. This means that a program that doesn't include `↩` won't have such changes in behavior. However, there will still be an observable difference between immutable data and the mutable types: code that creates a mutable value (for example, a block function `{𝕩}`) creates a different one each time, so that two different instances don't match (`≡`) each other. Data values created at different times may match, but mutable values never will. -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. +An array is considered immutable because its shape, and what elements it contains, cannot change. An array has no identity outside these properties (and possibly its fill element), so an array with a different shape or different elements would simply be a different array. However, any element of an array could be mutable, in which case the behavior of the array would change with respect to the operation of selecting that element and calling it or accessing a field. ## Data types @@ -87,3 +88,7 @@ A function is called with one or two arguments. A data value (number, character, ### Modifiers A 1-modifier is called with one operand, while a 2-modifier is called with two. In contrast to functions, these are distinct types, and it is impossible to have a value that can be called with either one or two operands. Also in contrast to functions, data values cannot be called as modifiers: they will cause an error if called this way. + +## Namespaces + +Functions and modifiers have internal scopes which they can manipulate (by defining and modifying variables) to save and update information. Namespaces let the programmer to expose this state more directly: identifiers in a namespace may be exported, allowing code outside the namespace to read their values. They are described in detail [here](namespace.md). diff --git a/docs/doc/types.html b/docs/doc/types.html index c1786660..f228bd0f 100644 --- a/docs/doc/types.html +++ b/docs/doc/types.html @@ -13,33 +13,37 @@ <li><a href="#functions">Function</a></li> <li>1-<a href="#modifiers">Modifier</a></li> <li>2-<a href="#modifiers">Modifier</a></li> +<li><a href="#namespaces">Namespace</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'> +<p>The first three types, called <em>data types</em>, are immutable; the others are mutable. Functions and modifiers together are the <em>operation types</em>. Types other than the array 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 640 212'> <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'/> + <path d='M0 12A12 12 0 0 1 12 0L320.8 0A12 12 0 0 1 332.8 12L332.8 56A12 12 0 0 0 344.8 68L500 68A12 12 0 0 1 512 80L512 124A12 12 0 0 1 500 136L12 136A12 12 0 0 1 0 124Z' class='yellow'/> + <rect width='496' height='52' x='8' y='8' rx='9px' class='purple'/> + <rect width='500' height='56' x='6' y='74' rx='10px' class='green'/> + <rect width='372' height='44' x='12' y='80' rx='8px' 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> + <text x='85.333' y='34' dy='0.35em'>Number</text> + <text x='256' y='34' dy='0.35em'>Character</text> + <text x='426.667' y='34' dy='0.35em'>Array</text> + <text x='64' y='102' dy='0.35em'>Function</text> + <text x='192' y='102' dy='0.35em'>1-modifier</text> + <text x='320' y='102' dy='0.35em'>2-modifier</text> + <text x='448' y='102' dy='0.35em'>Namespace</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> + <text class='purple' x='352' y='-10.2' dy='0.35em'>Data</text> + <text class='green' x='384' y='149.6' dy='0.35em'>Mutable</text> + <text class='bluegreen' x='192' y='149.6' dy='0.35em'>Operation</text> + <text class='yellow' x='140.8' y='-20.4' dy='0.35em'>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 "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.</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> +<p>The reason operations and namespaces are called "mutable" is that the values obtained from them—by calling an operation on particular arguments or reading a field from a namespace—may change over the course of the program. This property is caused by variable modification <code><span class='Gets'>↩</span></code>, which can directly change a namespace field, or change the behavior of an operation that uses the modified variable. This means that a program that doesn't include <code><span class='Gets'>↩</span></code> won't have such changes in behavior. However, there will still be an observable difference between immutable data and the mutable types: code that creates a mutable value (for example, a block function <code><span class='Brace'>{</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code>) creates a different one each time, so that two different instances don't match (<code><span class='Function'>≡</span></code>) each other. Data values created at different times may match, but mutable values never will.</p> +<p>An array is considered immutable because its shape, and what elements it contains, cannot change. An array has no identity outside these properties (and possibly its fill element), so an array with a different shape or different elements would simply be a different array. However, any element of an array could be mutable, in which case the behavior of the array would change with respect to the operation of selecting that element and calling it or accessing a field.</p> <h2 id="data-types">Data types</h2> <p>Data types—numbers, characters, and arrays—are more like "things" than "actions". If called as a function, a value of one of these types simply returns itself. Data can be uniquely represented, compared for equality, and ordered using BQN's array ordering; in contrast, determining whether two functions always return the same result can be undecidable. For arrays, these properties apply only if there are no operations inside. We might say that "data" in BQN refers to numbers, characters, and arrays of data.</p> <h3 id="numbers">Numbers</h3> @@ -64,3 +68,5 @@ <p>A function is called with one or two arguments. A data value (number, character, or array) can also be called the same way, but only a function takes any action when passed arguments, as data just returns itself. Both the one-argument and two-argument calls are considered function calls, and it's common for a function to allow both. A function that always errors in one case or the other might be called a one-argument or two-argument function, depending on which case is allowed.</p> <h3 id="modifiers">Modifiers</h3> <p>A 1-modifier is called with one operand, while a 2-modifier is called with two. In contrast to functions, these are distinct types, and it is impossible to have a value that can be called with either one or two operands. Also in contrast to functions, data values cannot be called as modifiers: they will cause an error if called this way.</p> +<h2 id="namespaces">Namespaces</h2> +<p>Functions and modifiers have internal scopes which they can manipulate (by defining and modifying variables) to save and update information. Namespaces let the programmer to expose this state more directly: identifiers in a namespace may be exported, allowing code outside the namespace to read their values. They are described in detail <a href="namespace.html">here</a>.</p> |
