diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-06-11 20:08:12 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-06-11 20:08:12 -0400 |
| commit | b6bcf214e638fd36ef7d76c9f573a84e6e016482 (patch) | |
| tree | a435e4f0afed7266b868798e51b792c4600fabe1 /doc | |
| parent | 383298b70274c5ac22eb2100aad7f6cd8eeca02d (diff) | |
Nothing but edits yet again
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/assert.md | 2 | ||||
| -rw-r--r-- | doc/repeat.md | 2 | ||||
| -rw-r--r-- | doc/take.md | 13 | ||||
| -rw-r--r-- | doc/train.md | 22 | ||||
| -rw-r--r-- | doc/transpose.md | 27 | ||||
| -rw-r--r-- | doc/types.md | 12 |
6 files changed, 46 insertions, 32 deletions
diff --git a/doc/assert.md b/doc/assert.md index f193be21..14e4cf72 100644 --- a/doc/assert.md +++ b/doc/assert.md @@ -38,6 +38,6 @@ The `Catch` modifier allows you to handle errors in BQN (at present, it's the on 0.5 ⌽⎊⊣ ↕6 # A two-argument example -Catch doesn't know anything about what an error *is*, just whether there was one or not. In fact, the idea of error message doesn't feature at all in core BQN: it's purely part of the language environment. So you need a system value to access information about the error. Right now the only one is `•CurrentError`, which is a function that returns a message for the error currently caught (if any). +Catch doesn't know anything about what an error *is*, just whether there was one or not. In fact, the idea of an error message doesn't feature at all in core BQN: it's purely part of the language environment. So you need a system value to access information about the error. Right now the only one is `•CurrentError`, which is a function that returns a message for the error currently caught (if any). ⌽⎊•CurrentError 2 diff --git a/doc/repeat.md b/doc/repeat.md index 2c357acd..bf14c7ca 100644 --- a/doc/repeat.md +++ b/doc/repeat.md @@ -1,6 +1,6 @@ *View this file with results and syntax highlighting [here](https://mlochbaum.github.io/BQN/doc/repeat.html).* -# The Repeat modifier +# Repeat Repeat (`⍟`) is a 2-modifier that applies its operand function `𝔽` multiple times. diff --git a/doc/take.md b/doc/take.md index 0244051e..2e549b67 100644 --- a/doc/take.md +++ b/doc/take.md @@ -47,18 +47,19 @@ The basic idea of Take (`↑`) is to get the first few elements of a list, while - `𝕩` can be an atom, or array of any rank (the result will be an array). - `𝕨` can be negative to take or drop from the end instead of the beginning. - For Take, if `𝕨` is larger than the length of `𝕩`, then [fills](fill.md) are added. -- `𝕨` can have multiple numbers corresponding to leading axes of `𝕩`. +- `𝕨` can have multiple numbers corresponding to [leading](leading.md) axes of `𝕩`. - `𝕨` is allowed to be longer than the rank of `𝕩`; `𝕩` will be extended to fit. -These extensions can be combined as well, so there are a lot of possibilities. A good picture to have in mind is cutting out a corner of the array `𝕩`. This is because the result `𝕨↑𝕩` or `𝕨↓𝕩` always aligns with one side of `𝕩` along each axis, so it aligns with the corner where those sides meet. +These extensions can be combined as well, so there are a lot of possibilities. A good picture to have in mind is cutting out a corner of the array `𝕩`. This is because the result `𝕨↑𝕩` or `𝕨↓𝕩` always aligns with one side of `𝕩` along each axis, so it also aligns with the corner where those sides meet. The result `d↓𝕩` is always the same as `t↑𝕩` for some other argument `t`, but computing `t` wouldn't be too convenient. The reverse isn't true: only Take can insert fills, so results that include them can't come from Drop. ## One axis -Let's start with a natural number `𝕨`. Take gives the first `𝕨` major cells of `𝕩` (or elements of a list), while Drop gives all but the first `𝕨`. +Let's start with a natural number `𝕨`. Take gives the first `𝕨` [major cells](array.md#cells) of `𝕩` (or elements of a list), while Drop gives all but the first `𝕨`. 4 ↑ "take and drop" + 4 ↓ "take and drop" 1 ↓ >"maj"‿"orc"‿"ell" @@ -81,7 +82,7 @@ If `𝕩` is an atom or unit array, it's converted to a list first. For Take thi ### Negative argument -If `𝕨` is negative then wraps around the other side to take or drop from the end of `𝕩`. It's a lot like negative indices in [Select](select.md) (`⊏`), but while negative indices are asymmetric—`0` is the first entry but `¯1` is the last—this case is symmetric. It's because the place to cut is always *before* the index `𝕨`, cancelling out the negative index asymmetry. +If `𝕨` is negative, it wraps around the other side to take or drop from the end of `𝕩`. It's a lot like negative indices in [Select](select.md) (`⊏`), but while negative indices are asymmetric—`0` is the first entry but `¯1` is the last—this case is symmetric. It's because the place to cut is always *before* the index `𝕨`, cancelling out the negative index asymmetry. 3 ↑ "abcdeEDCBA" @@ -95,13 +96,13 @@ What about `0`? It behaves like it's both positive *and* negative. For Take, the 0 ↓ 4‿3‿2 # Everything -If `|𝕨` is too large, then Take will insert fills at the beginning to keep the result aligned with `𝕩` at the end. Drop returns an empty array as in the positive case. So unlike [Rotate](reverse.md) (`⌽`), which is completely cyclical, Take and Drop work cyclically only around 0. +If `|𝕨` is too large, then Take will insert fills at the beginning to keep the result aligned with `𝕩` at the end. Drop returns an empty array as in the positive case. So unlike [Rotate](reverse.md) (`⌽`), which is completely cyclical, Take and Drop look cyclic only around 0. ¯6 ↑ "xy" ## Multiple axes -In the general case `𝕨` is a list of integers. They're matched with the leading axes of `𝕩`, so that each affects one axis independently from the others. +In the general case `𝕨` is a list of integers. They're matched with the [leading axes](leading.md) of `𝕩`, so that each affects one axis independently from the others. ⊢ m ← (10×↕5) +⌜ ↕7 diff --git a/doc/train.md b/doc/train.md index 62127d30..4d0dfde2 100644 --- a/doc/train.md +++ b/doc/train.md @@ -2,7 +2,7 @@ # Function trains -Trains are an important aspect of BQN's [tacit](tacit.md) programming capabilities. In fact, a crucial one: with trains and the [identity functions](identity.md) Left (`⊣`) and Right (`⊢`), a fully tacit program can express any explicit function whose body is a statement with `𝕨` and `𝕩` used only as arguments (that is, there are no assignments and `𝕨` and `𝕩` are not used in operands or lists. Functions with assignments may have too many variables active at once to be directly translated but can be emulated by constructing lists. But it's probably a bad idea). Without trains it isn't possible to have two different functions that each use both arguments to a dyadic function. With trains it's perfectly natural. +Trains are an important aspect of BQN's [tacit](tacit.md) programming capabilities. In fact, a crucial one: with trains, the [identity functions](identity.md) Left (`⊣`) and Right (`⊢`), and [Constant](constant.md) (`˙`), a fully tacit program can express any explicit function whose body is a statement with `𝕨` and `𝕩` used only as arguments (that is, there are no assignments and `𝕨` and `𝕩` are not used in operands or lists. Functions with assignments may have too many variables active at once to be directly translated but can be emulated by constructing lists. But it's probably a bad idea). Without trains it isn't possible to have two different functions that each use both arguments to a dyadic function. With trains it's perfectly natural. BQN's trains are the same as those of Dyalog APL, except that Dyalog is missing the minor convenience of BQN's [Nothing](expression.md#nothing) (`·`). There are many Dyalog-based documents and videos on trains you can view on the [APL Wiki](https://aplwiki.com/wiki/Train). @@ -14,9 +14,9 @@ Trains are an adaptation of the mathematical convention that, for example, two f So given a list of the first few natural numbers, that *same* list *plus* its *reverse* gives a list of just one number repeated many times. I'm sure if I were [Gauss](https://en.wikipedia.org/wiki/Carl_Friedrich_Gauss#Anecdotes) I'd be able to find some clever use for that fact. The mathematical convention extends to any central operator and any number of function arguments, which in BQN means we use any three functions, and call the train with a left argument as well—the only numbers of arguments BQN syntax allows are 1 and 2. - 7 (+≍-) 2 + 7 (+⋈-) 2 -Here [Couple](couple.md) (`≍`) is used to combine two units into a list, so we get seven plus and minus two. It's also possible to leave out the leftmost function of a train, or replace it with `·`. In this case the function on the right is called, then the other function is called on its result—it's identical to the mathematical composition `∘`, which is also part of BQN. +[Pair](pair.md) (`⋈`) makes a list from two values, so we get seven plus and minus two. It's also possible to leave out the leftmost function of a train, or replace it with `·`. In this case the function on the right is called, then the other function is called on its result—it's identical to the mathematical [composition](compose.md) `∘`, which is also part of BQN. (∾⌽) "ab"‿"cde"‿"f" (·∾⌽) "ab"‿"cde"‿"f" @@ -26,23 +26,23 @@ The three functions `∾⌽`, `·∾⌽`, and `∾∘⌽` are completely identic ## Longer trains -Function application in trains, as in other contexts, shares the lowest precedence level with assignment. Modifiers and strands (with `‿`) have higher precedence, so they are applied before forming any trains. Once this is done, an expression is a *subject expression* if it ends with a subject and a *function expression* if it ends with a function (there are also modifier expressions, which aren't relevant here). A train is any function expression with multiple functions or subjects in it: while we've seen examples with two or three functions, any number are allowed. +Function application in trains, as in other contexts, shares the lowest precedence level with assignment. Modifiers and strands (with `‿`) have higher precedence, so they are applied before forming any trains. Once this is done, an expression is a *subject expression* if it ends with a subject and a *function expression* if it ends with a function (a lone modifier can also be an expression, which isn't either of these). A train is any function expression with multiple functions or subjects in it: while we've seen examples with two or three functions, any number are allowed. -Subject expressions are the domain of "old-school" APL, and just apply one function after another to a subject, possibly assigning some of the results (that's the top-level picture—anything can still happen within parentheses). Subjects other than the first appear only as left arguments to functions, which means that two subjects can't appear next to each other because the one on the left would have no corresponding function. Here's an example from the compiler (at one point), with functions and assignments numbered in the order they are applied and their arguments marked with `«»`, and a fully-parenthesized version shown below. +Subject expressions are the domain of "old-school" APL, and just apply one function after another to a subject, possibly assigning some of the results (that's the top-level picture—anything can still happen within parentheses). Subjects other than the first appear only as left arguments to functions, which means that two subjects can't appear next to each other because the one on the left would have no corresponding function. Here's an example from BQN's compiler, with functions and assignments numbered in the order they are applied and their arguments marked with `«»`, and a fully-parenthesized version shown below. cn←pi∾lt←/𝕩≥ci←vi+nv «6 «5 «43«2 «1 «0» cn←(pi∾(lt←(/(𝕩≥(ci←(vi+nv)))))) -Function expressions have related but different rules, driven by the central principle that functions can be used as "arguments". Because roles can no longer be used to distinguish functions from their arguments, every function is assumed to have two arguments unless there's nothing to the left of it, or an assignment. In trains, assignments can't appear in the middle, only at the left side after all the functions have been applied. Here's another example from the compiler. Remember that for our purposes `` ⌈` `` behaves as a single component. +Function expressions have related but different rules, driven by the central principle that functions can be used as "arguments". Because roles can no longer be used to distinguish functions from their arguments, every function is assumed to have two arguments unless there's nothing to the left of it, or an assignment. In trains, assignments can't appear in the middle, only at the left side apart from all the functions. Here's another example from the compiler. Remember that for our purposes `` ⌈` `` behaves as a single component. ⊢>¯1»⌈` «1 «0» ⊢>(¯1»⌈`) -In a train, arguments alternate strictly with combining functions between them. Arguments can be either functions or subjects, except for the rightmost one, which has to be a function to indicate that the expression is a train. Trains tend to be shorter than subject expressions partly because to keep track of this alternation in a train of all functions, you need to know where each function is relative to the end of the train (subjects like the `¯1` above only occur as left arguments, so they can also serve as anchors). +In a train, arguments alternate strictly with combining functions between them. Arguments can be either functions or subjects, except for the rightmost one, which has to be a function to indicate that the expression is a train. Trains tend to be shorter than subject expressions partly because this rule leads to some difficulty when reading. To keep track of the alternation in a train of all functions, you need to know where each function is relative to the end of the train (subjects like the `¯1` above only occur as left arguments, so they can also serve as anchors). ## Practice training @@ -54,7 +54,7 @@ The train `` ⊢>¯1»⌈` `` is actually a nice trick to get the result of [Mar So—although not all trains simplify so much—this confusing train is just `` {𝕩>¯1»⌈`𝕩} ``! Why would I write it in such an obtuse way? To someone used to working with trains, the function `` (⊢>¯1»⌈`) `` isn't any more complicated to read: `⊢` in an argument position of a train just means `𝕩` while `` ⌈` `` will be applied to the arguments. Using the train just means slightly shorter code and two fewer `𝕩`s to trip over. -This function's argument is Classify (`⊐`) of some list (in fact this technique also works on the [index-of](search.md#index-of)-self `𝕩⊐𝕩`). Classify moves along its argument, giving each major cell a number: the first unused natural number if that value hasn't been seen yet, and otherwise the number chosen when it was first seen. It can be implemented as `⍷⊐⊢`, another train! +This function's argument is Classify (`⊐`) of some list (in fact this technique also works on the [index-of](search.md#index-of)-self `𝕩⊐𝕩`). Classify moves along its argument, giving each major cell a number: the first unused natural number if that value hasn't been seen yet, and otherwise the number chosen when it was first seen. It can in turn be implemented as `⍷⊐⊢`, another train! ⊢ sc ← ⊐ "tacittrains" @@ -80,17 +80,17 @@ But we also saw the length-2 train `∾⌽` above. Even-length trains consist of ⍷∧| 3‿4‿¯3‿¯2‿0 -If it doesn't have to be a function, it's easiest to write it all out! Let's assume we want a tacit function instead. With three one-argument functions, we can't use a 3-train, as the middle function in a 3-train always has two arguments. Instead, we will compose the functions with 2-trains. Composition is associative, meaning that this can be done starting at either the left or the right. +If it doesn't have to be a function, that's easiest to write it out! Let's assume we want a tacit function instead. With three one-argument functions, we can't use a 3-train, as the middle function in a 3-train always has two arguments. Instead, we will compose the functions with 2-trains. Composition is associative, meaning that this can be done starting at either the left or the right. ((⍷∧)|) 3‿4‿¯3‿¯2‿0 (⍷(∧|)) 3‿4‿¯3‿¯2‿0 -We might make the first train above easier to read by using Atop (`∘`) instead of a 2-train. Atop is a 2-modifier, so it doesn't need parentheses when used in a train. The second train can also be changed to `⍷∧∘|` in the same way, but there is another option: the rightmost train `∧|` can be expanded to `·∧|`. After this it's an odd-length train in the last position, and doesn't need parentheses anymore. +We might make the first train above easier to read by using [Atop](compose.md#atop) (`∘`) instead of a 2-train. Atop is a 2-modifier, so it doesn't need parentheses when used in a train. The second train can also be changed to `⍷∧∘|` in the same way, but there is another option: the rightmost train `∧|` can be expanded to `·∧|`. After this it's an odd-length train in the last position, and doesn't need parentheses anymore. (⍷∘∧|) 3‿4‿¯3‿¯2‿0 (⍷·∧|) 3‿4‿¯3‿¯2‿0 -These two forms have a different emphasis, because the first breaks into subfunctions `⍷∘∧` and `|` and the second into `⍷` and `∧|`. It's more common to use `⍷∘∧` as a unit than `∧|`, so in this case `⍷∘∧|` is probably the better train. +These two forms have a different emphasis, because the first breaks into subfunctions `⍷∘∧` and `|` and the second into `⍷` and `∧|`. It's more common to use `⍷∘∧` together than `∧|`, so in this case `⍷∘∧|` is probably the better train. Many one-argument functions strung together is [a major weakness](../commentary/problems.md#trains-dont-like-monads) for train syntax. If there are many such functions it's probably best to stick with a block function instead! diff --git a/doc/transpose.md b/doc/transpose.md index e11ab359..fdbfdeca 100644 --- a/doc/transpose.md +++ b/doc/transpose.md @@ -28,7 +28,7 @@ BQN's transpose takes the first axis of `𝕩` and moves it to the end. ≢ ⍉ a23456 -In terms of the argument data as given by [Deshape](reshape.md#deshape) (`⥊`), this looks like a simple 2-dimensional transpose: one axis is exchanged with a compound axis made up of the other axes. Here we transpose a rank 3 matrix: +In terms of the index-ordered elements as given by [Deshape](reshape.md#deshape) (`⥊`), this looks like a simple 2-dimensional transpose: one axis is exchanged with a compound axis made up of the other axes. Here we transpose a rank 3 matrix: a322 ← 3‿2‿2⥊↕12 ⋈⟜⍉ a322 @@ -45,7 +45,7 @@ To exchange multiple axes, use the [Repeat](repeat.md) modifier. A negative powe In fact, we have `≢⍉⍟k a ←→ k⌽≢a` for any whole number `k` and array `a`. -To move axes other than the first, use the Rank modifier in order to leave initial axes untouched. A rank of `k>0` transposes only the last `k` axes while a rank of `k<0` ignores the first `|k` axes. +To move axes other than the first, use the [Rank modifier](rank.md) in order to leave initial axes untouched. A rank of `k>0` transposes only the last `k` axes while a rank of `k<0` ignores the first `|k` axes. ≢ ⍉⎉3 a23456 @@ -57,7 +57,7 @@ Using these forms (and the [Rank](shape.md) function), we can state BQN's genera a MP b ←→ ⍉⍟(1-=a) (⍉b) MP (⍉⁼a) -Certainly not as concise as APL's version, but not a horror either. BQN's rule is actually more parsimonious in that it only performs the axis exchanges necessary for the computation: it moves the two axes that will be paired with the matrix product into place before the product, and directly exchanges all axes afterwards. Each of these steps is equivalent in terms of data movement to a matrix transpose, the simplest nontrivial transpose to perform. Also remember that for two-dimensional matrices both kinds of transposition are the same, so that APL's simpler rule `MP ≡ MP⌾⍉˜` holds in BQN. +Certainly not as concise as APL's version, but not a horror either. BQN's rule is actually more parsimonious in that it only performs the axis exchanges necessary for the computation: it moves the two axes that will be paired with the matrix product into place before the product, and directly exchanges all axes afterwards. Each of these steps is equivalent in terms of data movement to a matrix transpose, the simplest nontrivial transpose to perform. Also remember that for two-dimensional matrices both kinds of transposition are the same, so that APL's simpler rule `MP ≡ MP⌾⍉˜` holds in BQN on rank 2. Axis permutations of the types we've shown generate the complete permutation group on any number of axes, so you could produce any transposition you want with the right sequence of monadic transpositions with Rank. However, this can be unintuitive and tedious. What if you want to transpose the first three axes, leaving the rest alone? With monadic Transpose you have to send some axes to the end, then bring them back to the beginning. For example [following four or five failed tries]: @@ -67,7 +67,7 @@ In a case like this the dyadic version of `⍉`, called Reorder Axes, is much ea ## Reorder Axes -Transpose also allows a left argument that specifies a permutation of `𝕩`'s axes. For each index `p←i⊑𝕨` in the left argument, axis `i` of `𝕩` is used for axis `p` of the result. Multiple argument axes can be sent to the same result axis, in which case that axis goes along a diagonal of `𝕩`, and the result will have a lower rank than `𝕩`. +Transpose also allows a left argument that specifies a permutation of `𝕩`'s axes. For each index `p←i⊑𝕨` in the left argument, axis `i` of `𝕩` is used for axis `p` of the result. Multiple argument axes can be sent to the same result axis, in which case that axis goes along a diagonal of `𝕩`, and the result will have a lower rank than `𝕩` (see the next section). ≢ 1‿3‿2‿0‿4 ⍉ a23456 @@ -87,12 +87,25 @@ In particular, the case with only one axis specified is interesting. Here, the f Finally, it's worth noting that, as monadic Transpose moves the first axis to the end, it's equivalent to Reorder Axes with a "default" left argument: `(=-1˙)⊸⍉`. +### Taking diagonals + +When `𝕨` contains an axis index more than once, the corresponding axes of `𝕩` will *all* be sent to that axis of the result. This isn't a special case: it follows the same rule that `i⊑𝕨⍉𝕩` is `(𝕨⊏i)⊑𝕩`. Only the result shape has to be adjusted for this case: the length along a result axis is the minimum of all the axes of `𝕩` that go into it, because any indices outside this range will be out of bounds along at least one axis. + +A bit abstract. This rule is almost always used simply as `0‿0⍉𝕩` to get the main diagonal of a matrix. + + ⊢ a ← 3‿5⥊'a'+↕15 + + 0‿0 ⍉ a + + ⟨2⟩⊑0‿0⍉a # Single index into result + ⟨2,2⟩⊑a # is like a doubled index into a + ## Definitions Here we define the two valences of Transpose more precisely. -An atom right argument to either valence of Transpose is always enclosed to get an array before doing anything else. +An atom right argument to Transpose or Reorder Axes is always [enclosed](enclose.md) to get an array before doing anything else. -Monadic transpose is identical to `(=-1˙)⊸⍉`, except that if `𝕩` is a unit it is returned unchanged (after enclosing, if it's an atom) rather than giving an error. +Monadic Transpose is identical to `(=-1˙)⊸⍉`, except that if `𝕩` is a unit it's returned unchanged (after enclosing, if it's an atom) rather than giving an error. -In Reorder Axes, `𝕨` is a number or numeric array of rank 1 or less, and `𝕨≤○≠≢𝕩`. Define the result rank `r←(=𝕩)-+´¬∊𝕨` to be the right argument rank minus the number of duplicate entries in the left argument. We require `∧´𝕨<r`. Bring `𝕨` to full length by appending the missing indices: `𝕨∾↩𝕨(¬∘∊˜/⊢)↕r`. Now the result shape is defined to be `⌊´¨𝕨⊔≢𝕩`. Element `i⊑z` of the result `z` is element `(𝕨⊏i)⊑𝕩` of the argument. +In Reorder Axes, `𝕨` is a number or numeric array of rank 1 or less, and `𝕨≤○≠≢𝕩`. Define the result rank `r←(=𝕩)-+´¬∊𝕨` to be the rank of `𝕩` minus the number of duplicate entries in `𝕨`. We require `∧´𝕨<r`. Bring `𝕨` to full length by appending the missing indices: `𝕨∾↩𝕨(¬∘∊˜/⊢)↕r`. Now the result shape is defined to be `⌊´¨𝕨⊔≢𝕩`. Element `i⊑z` of the result `z` is element `(𝕨⊏i)⊑𝕩` of the argument. diff --git a/doc/types.md b/doc/types.md index 27b31f89..0e1a97ca 100644 --- a/doc/types.md +++ b/doc/types.md @@ -46,7 +46,7 @@ FS ← {𝕩 Enc˜ "g"Attr⟨"font-size",(Fmt𝕨)∾"px"⟩} 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](lexical.md#mutation) 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](match.md) (`≡`) each other. Data values created at different times may match, but mutable values never will. -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](fill.md)), 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. +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](fill.md), which also can't change), 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 @@ -54,7 +54,7 @@ Data types—numbers, characters, and arrays—are more like "things" than "acti ### Numbers -The BQN spec allows for different numeric models to be used, but requires there to be only one numeric type from the programmer's perspective: while programs can often be executed faster by using limited-range integer types, there is no need to expose these details to the programmer. Existing BQN implementations are based on [double-precision floats](https://en.wikipedia.org/wiki/IEEE-754), like Javascript or Lua. +The BQN spec allows for different numeric models to be used, but requires there to be only one numeric type from the programmer's perspective: while programs can often be executed faster by using limited-range integer types, there is no need to expose these details to the programmer. Existing BQN implementations use [double-precision floats](https://en.wikipedia.org/wiki/IEEE-754), like Javascript or Lua. ### Characters @@ -63,17 +63,17 @@ A character in BQN is always a [Unicode](https://en.wikipedia.org/wiki/Unicode) Addition and subtraction [treat](arithmetic.md#character-arithmetic) characters as an [affine space](http://videocortex.io/2018/Affine-Space-Types/) relative to the linear space of numbers. This means that: * A number can be added to or subtracted from a character. * Two characters can be subtracted to get the distance between them—a number. -Other linear combinations such as adding two characters or negating a character are not allowed. You can check whether an application of `+` or `-` on numbers and characters is allowed by applying the same function to the "characterness" of each value: `0` for a number and `1` for a character. The result will be a number if this application gives `0` and a character if this gives `1`, and otherwise the operation is not allowed. +Other linear combinations such as adding two characters or negating a character are not allowed. You can check whether an application of `+` or `-` on numbers and characters is allowed by applying the same function to the "characterness" of each value: 0 for a number and 1 for a character. The result will be a number if the application gives 0 and a character if it gives 1, and otherwise the operation is not allowed. ### Arrays *[Full documentation](array.md).* -A BQN array is a multidimensional arrangement of data. This means it has a certain [*shape*](shape.md), which is a finite list of natural numbers giving the length along each axis, and it contains an *element* for each possible [*index*](indices.md), which is a choice of one natural number that's less than each axis length in the shape. The total number of elements, or *bound*, is then the product of all the lengths in the shape. The shape may have any length including zero, and this shape is known as the array's *rank*. An array of rank 0, which always contains exactly one element, is called a *unit*, while an array of rank 1 is called a *list* and an array of rank 2 is called a *table*. +A BQN array is a multidimensional arrangement of data. This means it has a certain [*shape*](shape.md), which is a finite list of natural numbers giving the length along each axis, and it contains an *element* for each possible [*index*](indices.md), which is a choice of one natural number that's less than each axis length in the shape. The total number of elements, or *bound*, is then the product of all the lengths in the shape. The shape may have any length including zero, and this shape is known as the array's *rank*. An array of rank 0, which always contains exactly one element, is called a [*unit*](enclose.md#whats-a-unit), while an array of rank 1 is called a *list* and an array of rank 2 is called a *table*. Each array—empty or nonempty—has an inferred property called a [*fill*](fill.md). The fill either indicates what element should be used to pad an array, or that such an element is not known and an error should result. Fills can be used by [Take](take.md) (`↑`), the two [Nudge](shift.md) functions (`»«`), [Merge](couple.md) (`>`), and [Reshape](reshape.md) (`⥊`). -Arrays are value types (or immutable), so that there is no way to "change" the shape or elements of an array. An array with different properties is a different array. As a consequence, arrays are an inductive type, and it's not possible for an array to contain itself, or contain an array that contains itself, and so on. However, it is possible for an array to contain a function or other operation that has access to the array through a variable, and in this sense an array can "know about" itself. +Arrays are value types (or immutable), so that there is no way to "change" the shape or elements of an array. An array with different properties is a different array. As a consequence, arrays are an inductive type, and it's not possible for an array to contain itself, or contain an array that contains itself, and so on. However, it is possible for an array to contain a function or other mutable value that has access to the array through a variable, and in this sense an array can "know about" itself. Different elements of an array should not influence each other. While some APLs force numbers placed in the same array to a common representation, which may have different precision properties, BQN values must not change behavior when placed in an array. However, this doesn't preclude changing the storage type of an array for better performance: for example, in a BQN implementation using 64-bit floats, an array whose elements are all integers that fit in 32-bit int range might be represented as an array of 32-bit ints. @@ -83,7 +83,7 @@ Different elements of an array should not influence each other. While some APLs An operation is either a function or modifier, and can be applied to *inputs*—which are called *arguments* for functions and *operands* for modifiers—to obtain a result. During this application an operation might also change variables within its scope and call other operations, or cause an error, in which case it doesn't return a result. There is one type of call for each of the three operation types, and an operation will give an error if it is called in a way that doesn't match its type. -In BQN syntax the result of a function has a subject role and the result of a modifier has a function role. However, the result can be any value at all: roles take place at the syntactic level, which has no bearing on types and values in the semantic level. This distinction is discussed further in [Mixing roles](context.md#mixing-roles). +In BQN syntax the result of function application has a subject role and the result of modifier application has a function role. However, the result value can still be anything at all: roles apply at the syntactic level, which has no bearing on types and values in the semantic level. This distinction is discussed further in [Mixing roles](context.md#mixing-roles). ### Functions |
