From b6bcf214e638fd36ef7d76c9f573a84e6e016482 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 11 Jun 2022 20:08:12 -0400 Subject: Nothing but edits yet again --- docs/doc/assert.html | 2 +- docs/doc/repeat.html | 4 ++-- docs/doc/take.html | 15 ++++++++------- docs/doc/train.html | 22 +++++++++++----------- docs/doc/transpose.html | 32 +++++++++++++++++++++++++------- docs/doc/types.html | 12 ++++++------ 6 files changed, 53 insertions(+), 34 deletions(-) (limited to 'docs') diff --git a/docs/doc/assert.html b/docs/doc/assert.html index 83d4b46c..ceccf72a 100644 --- a/docs/doc/assert.html +++ b/docs/doc/assert.html @@ -43,7 +43,7 @@ 0.5 6 # A two-argument example 0.5 -

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
 "⌽: Argument cannot be a unit"
 
diff --git a/docs/doc/repeat.html b/docs/doc/repeat.html index bf097430..62b69b2b 100644 --- a/docs/doc/repeat.html +++ b/docs/doc/repeat.html @@ -1,10 +1,10 @@ - BQN: The Repeat modifier + BQN: Repeat -

The Repeat modifier

+

Repeat

Repeat () is a 2-modifier that applies its operand function 𝔽 multiple times.

↗️
    »»» "ABCDE"
 "   AB"
diff --git a/docs/doc/take.html b/docs/doc/take.html
index 1dd895ff..1c976976 100644
--- a/docs/doc/take.html
+++ b/docs/doc/take.html
@@ -38,15 +38,16 @@
 
  • 𝕩 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 are added.
  • -
  • 𝕨 can have multiple numbers corresponding to leading axes of 𝕩.
  • +
  • 𝕨 can have multiple numbers corresponding to leading 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 𝕨.

    -↗️
        4  "take and drop"
    +

    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 𝕨.

    +↗️
        4  "take and drop"
     "take"
    +
         4  "take and drop"
     " and drop"
     
    @@ -77,7 +78,7 @@
     ⟨⟩
     

    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 (), 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 (), 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"
     "abc"
     
    @@ -94,12 +95,12 @@
         0  432  # Everything
     ⟨ 4 3 2 ⟩
     
    -

    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 (), 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 (), which is completely cyclical, Take and Drop look cyclic only around 0.

    ↗️
        ¯6  "xy"
     "    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 of 𝕩, so that each affects one axis independently from the others.

    ↗️
         m  (10×↕5) + 7
     ┌─                      
     ╵  0  1  2  3  4  5  6  
    diff --git a/docs/doc/train.html b/docs/doc/train.html
    index d45742b0..61e253ea 100644
    --- a/docs/doc/train.html
    +++ b/docs/doc/train.html
    @@ -5,7 +5,7 @@
     
     
     

    Function trains

    -

    Trains are an important aspect of BQN's tacit programming capabilities. In fact, a crucial one: with trains and the identity functions 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 programming capabilities. In fact, a crucial one: with trains, the identity functions Left () and Right (), and Constant (˙), 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 (·). There are many Dyalog-based documents and videos on trains you can view on the APL Wiki.

    2-train, 3-train

    Trains are an adaptation of the mathematical convention that, for example, two functions F and G can be added to get a new function F+G that applies as (F+G)(x) = F(x)+G(x). With a little change to the syntax, we can do exactly this in BQN:

    @@ -13,10 +13,10 @@ ⟨ 4 4 4 4 4 ⟩

    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 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
     ⟨ 9 5 ⟩
     
    -

    Here Couple () 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 () 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 , which is also part of BQN.

    ↗️
        (∾⌽) "ab""cde""f"
     "fcdeab"
         (·∾⌽) "ab""cde""f"
    @@ -26,20 +26,20 @@
     

    The three functions ∾⌽, ·∾⌽, and are completely identical: Join of Reverse. Why might we want three different ways to write the same thing? If we only want to define a function, there's hardly any difference. However, these three forms have different syntax, and might be easier or harder to use in different contexts. As we'll see, we can use inside a train without parenthesizing it, and string ·∾⌽ but not ∾⌽ together with other trains. Let's look at how the train syntax extends to longer expressions.

    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.

    -

    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.

    +

    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 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.

    cnpilt/𝕩civi+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

    The train ⊢>¯1»⌈` is actually a nice trick to get the result of Mark Firsts 𝕩 given the result of Classify 𝕩, without doing another search. Let's take a closer look, first by applying it mechanically. To do this, we apply each "argument" to the train's argument, and then combine them with the combining functions.

    ( > ¯1 » `) 𝕩
    @@ -47,7 +47,7 @@
     𝕩 > ¯1 » `𝕩
     

    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-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-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"
     ⟨ 0 1 2 3 0 0 4 1 3 5 6 ⟩
     
    @@ -76,19 +76,19 @@ ↗️
        ⍷∧| 34¯3¯20
     ⟨ 0 2 3 4 ⟩
     
    -

    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.

    ↗️
        ((⍷∧)|) 34¯3¯20
     ⟨ 0 2 3 4 ⟩
         ((∧|)) 34¯3¯20
     ⟨ 0 2 3 4 ⟩
     
    -

    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 () 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.

    ↗️
        (∧|) 34¯3¯20
     ⟨ 0 2 3 4 ⟩
         (·∧|) 34¯3¯20
     ⟨ 0 2 3 4 ⟩
     
    -

    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 for train syntax. If there are many such functions it's probably best to stick with a block function instead!

    ↗️
        {⍷∧|𝕩} 34¯3¯20
     ⟨ 0 2 3 4 ⟩
    diff --git a/docs/doc/transpose.html b/docs/doc/transpose.html
    index 807173ba..8c9841b3 100644
    --- a/docs/doc/transpose.html
    +++ b/docs/doc/transpose.html
    @@ -36,7 +36,7 @@
           a23456
     ⟨ 3 4 5 6 2 ⟩
     
    -

    In terms of the argument data as given by 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 (), 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  322⥊↕12
          a322
     ┌─                      
    @@ -71,7 +71,7 @@
     ⟨ 6 2 3 4 5 ⟩
     

    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 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
     ⟨ 2 3 5 6 4 ⟩
     
    @@ -82,14 +82,14 @@

    Using these forms (and the Rank function), we can state BQN's generalized matrix product swapping rule:

    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]:

    ↗️
         ¯2  a23456  # Restrict Transpose to the first three axes
     ⟨ 3 4 2 5 6 ⟩
     

    In a case like this the dyadic version of , called Reorder Axes, is much easier.

    Reorder Axes

    -

    Transpose also allows a left argument that specifies a permutation of 𝕩's axes. For each index pi𝕨 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 pi𝕨 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).

    ↗️
         13204  a23456
     ⟨ 5 2 4 3 6 ⟩
     
    @@ -109,8 +109,26 @@
     ⟨ 3 4 2 5 6 ⟩
     

    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 00𝕩 to get the main diagonal of a matrix.

    +↗️
         a  35'a'+↕15
    +┌─       
    +╵"abcde  
    +  fghij  
    +  klmno" 
    +        ┘
    +
    +    00  a
    +"agm"
    +
    +    200a  # Single index into result
    +'m'
    +    2,2a    # is like a doubled index into a
    +'m'
    +

    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.

    -

    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.

    -

    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 iz of the result z is element (𝕨i)𝕩 of the argument.

    +

    An atom right argument to Transpose or Reorder Axes is always enclosed to get an array before doing anything else.

    +

    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 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 iz of the result z is element (𝕨i)𝕩 of the argument.

    diff --git a/docs/doc/types.html b/docs/doc/types.html index 430aae1e..5dbab9bf 100644 --- a/docs/doc/types.html +++ b/docs/doc/types.html @@ -43,11 +43,11 @@

    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.

    -

    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.

    +

    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, 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

    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.

    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, 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, like Javascript or Lua.

    Characters

    A character in BQN is always a Unicode code point. BQN does not use encodings such as UTF-8 or UTF-16 for characters, although it would be possible to store arrays of integers or characters that correspond to data in these encodings. Because every code point corresponds to a single unit in UTF-32, BQN characters can be thought of as UTF-32 encoded.

    Addition and subtraction treat characters as an affine space relative to the linear space of numbers. This means that:

    @@ -55,17 +55,17 @@
  • 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.

    -

    A BQN array is a multidimensional arrangement of data. This means it has a certain shape, which is a finite list of natural numbers giving the length along each axis, and it contains an element for each possible index, 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, which is a finite list of natural numbers giving the length along each axis, and it contains an element for each possible index, 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.

    Each array—empty or nonempty—has an inferred property called a fill. 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 (), the two Nudge functions (»«), Merge (>), and Reshape ().

    -

    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.

    Operation types

    Full documentation.

    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.

    +

    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.

    Functions

    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.

    Modifiers

    -- cgit v1.2.3