From f469c6f9bd4c9cf3c2b8ce93c3f2331cdcdd589a Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 10 Jun 2022 22:42:44 -0400 Subject: More editing --- docs/doc/shift.html | 24 +++++++++++++----------- docs/doc/swap.html | 8 ++++---- docs/doc/syntax.html | 33 ++++++++++++++++++--------------- docs/doc/types.html | 6 +++--- 4 files changed, 38 insertions(+), 33 deletions(-) (limited to 'docs') diff --git a/docs/doc/shift.html b/docs/doc/shift.html index 5b72e865..8e8b3640 100644 --- a/docs/doc/shift.html +++ b/docs/doc/shift.html @@ -5,23 +5,25 @@

Shift functions

-

The shift functions « and » add major cells to one side an array, displacing cells on the opposite side and moving those in between. Shifts resemble but are more general than the bit-based shift operations used in low-level languages. They replace the APL pattern of a 2-wise reduction after appending or prepending an element (APL's 2≠/0,v translates to »v), one of the more common uses of 2-wise reduction.

+

The shift functions « and » add major cells to one side an array, displacing cells on the opposite side and moving those in between. Shifts resemble but are more general than the bit-based shift operations used in low-level languages. They replace the APL pattern of a 2-wise reduction after appending or prepending an element (APL's 2≠/0,v translates to »v); a nice version of this common pattern is one reason BQN is free to replace windowed reduction with the sometimes less convenient Windows.

The result of a shift function always has the same shape as 𝕩. The function adds major cells to the beginning (») or end («) of 𝕩, moving the cells already in 𝕩 to accomodate them. Some cells on the opposite side from those added will "fall off" and not be included in the result.

-↗️
    00 » 321             # Shift Before
+↗️
    00 » 321             # Shift Before
 ⟨ 0 0 3 ⟩
+
     "end" « "add to the "   # Shift After
 " to the end"
 

The cells to add come from 𝕨 if it's present, as shown above. Otherwise, a single cell of fill elements for 𝕩 is used. This kind of shift, which moves cells in 𝕩 over by just one, is called a "nudge".

-↗️
    » "abcd"   # Nudge
+↗️
    » "abcd"   # Nudge
 " abc"
+
     « 123    # Nudge Back
 ⟨ 2 3 0 ⟩
 
-

If 𝕨 is longer than 𝕩, some cells from 𝕨 will be discarded, as well as all of 𝕩. In this case 𝕨»𝕩 is (𝕩)𝕨 and 𝕨«𝕩 is (-≠𝕩)𝕨. For similar reasons, nudging an array of length 0 returns it unchanged.

+

If 𝕨 is longer than 𝕩, some cells from 𝕨 will be discarded, plus all of 𝕩. In this case 𝕨»𝕩 is (𝕩)𝕨 and 𝕨«𝕩 is (-≠𝕩)𝕨. For similar reasons, nudging an array of length 0 returns it unchanged.

Sequence processing with shifts

When working with a sequence of data such as text, daily measurements, or audio data, shift functions are generally the best way to handle the concept of "next" or "previous". In the following example s is shown alongside the shifted-right data »s, and each element is compared to the previous with -», which we see is the inverse of Plus Scan +`.

-↗️
    s  1224356
+↗️
    s  1224356
     s  »s
 ┌─               
 ╵ 1 2 2 4 3 5 6  
@@ -30,8 +32,8 @@
     -» s
 ⟨ 1 1 0 2 ¯1 2 1 ⟩
 
-    +` -» s
-⟨ 1 2 2 4 3 5 6 ⟩
+    +` -» s   # Same as s
+⟨ 1 2 2 4 3 5 6 ⟩
 

In this way » refers to a sequence containing the previous element at each position. By default the array's fill is used for the element before the first, and a right argument can be given to provide a different one.

↗️
     » s
@@ -59,7 +61,7 @@
 

A feature these examples all share is that they maintain the length of s. This is a common condition in sequence processing, particularly when the processed sequence needs to be combined or compared with the original in some way. However, it's not always the case. In some instances, for example when searching s to see if there is any value less than the previous, the list should get shorter during processing. In these cases, Windows () is usually a better choice.

Arithmetic and logical shifts

-

The glyphs « and », suggesting movement, were chosen for the same reasons as the digraphs << and >>, and can be used to implement the same operations on boolean lists.

+

The glyphs « and », suggesting movement, were chosen for the same reasons as the digraphs << and >> in C-like languages, and can be used to implement the same bit-shift operations on boolean lists.

↗️
     i  "10011011"-'0'
 ⟨ 1 0 0 1 1 0 1 1 ⟩
 
@@ -77,7 +79,7 @@
 ⟨ 1 1 1 1 0 0 1 1 ⟩
 

Other examples

-

In Take (), there's no way to specify the fill element when the result is longer than the argument. To take along the first axis with a specified, constant fill value, you can use Shift Before instead, where the right argument is an array of fills with the desired final shape.

+

In Take (), there's no way to specify the fill element when the result is longer than the argument. To take along the first axis with a specified, constant fill value, you can use Shift Before instead, where the right argument is an array of fills with the desired final shape (a more general approach is Under).

↗️
    "abc" » 5'F'
 "abcFF"
 
@@ -91,12 +93,12 @@ 2 +`» 1010 # Final value not created ⟨ 2 3 3 4 ⟩
-

The strides of an array are the distances between one element and the next along any given axis. It's the product of all axis lengths below that axis, since these are all the axes that have to be "skipped" to jump along the axis. The strides of an array 𝕩 are (×`1»⊢)𝕩.

+

The strides of an array are the distances between one element and the next along any given axis. It's the product of all axis lengths below that axis, since these are all the axes that have to be "skipped" to jump along the axis. The strides of an array 𝕩 are (×`1»⊢) 𝕩.

↗️
    (×`1»⊢) 5243
 ⟨ 24 12 3 1 ⟩
 

Higher rank

-

Shifting always works on the first axis of 𝕩 (which must have rank 1 or more), and shifts in major cells. A left argument can have rank equal to 𝕩, or one less than it, in which case it becomes a single cell of the result. With no left argument, a cell of fills 10𝕩 is nudged in.

+

Shifting always works on the first axis of 𝕩 (which must have rank 1 or more), and shifts in major cells. A left argument can have rank equal to 𝕩, or one less than it, in which case it becomes a single cell of the result. With no left argument, a cell of fills 10𝕩 is nudged in.

↗️
     a  (↕×´) 43
 ┌─         
 ╵ 0  1  2  
diff --git a/docs/doc/swap.html b/docs/doc/swap.html
index 190b0d0a..409de900 100644
--- a/docs/doc/swap.html
+++ b/docs/doc/swap.html
@@ -54,8 +54,8 @@
 
 
 
-

Since 𝕩 is always the left argument, these two definitions can be unified as {𝕩𝔽𝕨𝕩}, noting that Left becomes a plain identity function when the left argument 𝕨 isn't given.

-

Swap is arguably less transformative. Some common examples are -˜ and ÷˜, since these two functions run the wrong way for BQN's evaluation order. This is very often useful in tacit programming, and less useful for explicit code. While it sometimes allows for shorter code by making a pair of parentheses unnecessary (say, (a×b)-c is c-˜a×b), I personally don't think this is always a good idea. My opinion is that it should be used when it makes the semantics a better fit for BQN, but putting the primary argument on the right and a secondary or control argument on the left.

+

Since 𝕩 always becomes the left argument, these two definitions can be unified as {𝕩𝔽𝕨𝕩}, noting that Left returns 𝕨 if it's given and 𝕩 if not.

+

Swap is arguably less transformative. Some common examples are -˜ and ÷˜, since these two functions run the wrong way for BQN's evaluation order. This is very often useful in tacit programming, and less needed for explicit code. While it sometimes allows for shorter code by making a pair of parentheses unnecessary (say, (a×b)-c is c-˜a×b), I personally don't think this is always a good idea. My opinion is that it should be used when it makes the semantics a better fit for BQN, but putting the primary argument on the right and a secondary or control argument on the left.

↗️
    'a' ˜ 'b'
 "ba"
 
@@ -65,7 +65,7 @@
   + + +" 
         ┘
 
-

Self re-uses one argument twice. In this way it's a little like Over, which re-uses one function twice. A common combination is with Table, ⌜˜, so that the operand function is called on each combination of elements from the argument to form a square result. For example, =⌜˜ applied to n gives the identity matrix of size n.

+

Moving on, Self re-uses one argument twice. In this way it's a little like Over, which re-uses one function twice. A common combination is with Table, ⌜˜, so that the operand function is called on each combination of elements in 𝕩 to form a square result. For example, =⌜˜ applied to n gives the identity matrix of size n.

↗️
    ט 4
 16
 
@@ -76,4 +76,4 @@
   0 0 1  
         ┘
 
-

Note that Self isn't needed with Before () and After (), which essentially have a copy built in: for example FG 𝕩 is the same as FG˜ 𝕩 by definition.

+

Note that Self isn't needed with Before () and After (), which essentially have a copy built in: for example FG 𝕩 is the same as FG˜ 𝕩 by definition.

diff --git a/docs/doc/syntax.html b/docs/doc/syntax.html index 8798c1e4..6312fbbd 100644 --- a/docs/doc/syntax.html +++ b/docs/doc/syntax.html @@ -5,9 +5,9 @@

Syntax overview

-

BQN syntax consists of expressions where computation is done with a little organizing structure around them like assignment, functions, and list notation. Expressions are where the programmer is in control so the design tries to do as much as possible with them before introducing special syntax.

+

BQN syntax consists of expressions where computation is done, with a little organizing structure around them like assignment, functions, and list notation. Expressions are where the programmer is in control, so the design tries to do as much as possible with them before introducing special syntax.

Special glyphs

-

The following glyphs are used for BQN syntax. Primitives (built-in functions and modifiers) are not listed in this table, and have their own page. Digits, characters, and the underscore _ are used for numbers, and identifiers or variable names.

+

The following glyphs are used for BQN syntax. Primitives (built-in functions and modifiers) are not listed in this table, and have their own page. Digits, characters, and the underscore _ are used for numbers and variable names.

@@ -107,24 +107,27 @@

Comments

-

A comment starts with # that is not part of a string and continues to the end of the line.

+

A comment starts with a # that isn't part of a character or string literal, and continues to the end of the line.

+↗️
    '#' - 1  #This is the comment
+'"'
+

Constants

BQN has single-token notation for numbers, strings, and characters.

-

Numbers allow the typical decimal notation with ¯ for the negative sign (because - is a function) and e for scientific notation (or E, as numeric notation is case-insensitive). and π may be used as special numeric values. If complex numbers are supported, then they can be written with the components separated by i. However, no BQN to date supports complex numbers.

+

Numbers are written as decimals, allowing ¯ for the negative sign (because - is a function) and e or E for scientific notation. They must have digits before and after the decimal point (so, 0.5 instead of .5), and any exponent must be an integer. Two special numbers and π are supported, possibly with a minus sign. If complex numbers are supported (no implementation to date has them), then they can be written with the components separated by i or I.

↗️
     ¯π  0.5  5e¯1  1.5E3      # A list of numbers
 ⟨ ¯3.141592653589793 0.5 0.5 1500 ∞ ⟩
 
-

Strings are written with double quotes "", and characters with single quotes '' with a single character in between. A double quote within a string can be escaped by writing it twice; if two string literals are next to each other, they must be separated by a space. In contrast, character literals do not use escapes, as the length is already known.

+

Strings—lists of characters—are written with double quotes "", and characters with single quotes '' with a single character in between. Only one character ever needs to be escaped: a double quote in a string is written twice. So """" is a one-character string of ", and if two string literals are next to each other, they have to be separated by a space. Character literals don't have even one escape, as the length is already known. Other than the double quote, character and string literals can contain anything: newlines, null characters, or any other Unicode.

↗️
    ¨  "str"  "s't""r"  'c'  '''  '"'    # "" is an escape
 ⟨ 3 5 1 1 1 ⟩
 
     ¨  "a"  'a'    # A string is an array but a character isn't
 ⟨ 1 0 ⟩
 
-

The null character (code point 0) has a dedicated literal representation @. This character can be used to directly convert between characters and numeric code points, which among many other uses allows tricky characters to be entered by code point: for example, a non-breaking space is @+160. The character can also be entered as a character literal, but this will display differently in various editors and some tools may have trouble with a file directly containing a null, so it is best to use @ instead.

+

But including a null character in your source code is probably not a great idea for other reasons. The null character (code point 0) has a dedicated literal representation @. Null can be used with character arithmetic to directly convert between characters and numeric code points, which among many other uses allows tricky characters to be entered by code point: for example, a non-breaking space is @+160.

Expressions

Full documentation

-

BQN expressions are composed of subjects, functions, and modifiers, with parentheses to group parts into subexpressions. Functions can be applied to subjects or grouped into trains, while modifiers can be applied to subjects or functions. The most important kinds of application are:

+

BQN expressions are composed of subjects, functions, and modifiers, with parentheses to group parts into subexpressions. Functions can be applied to subjects or grouped into trains, while modifiers can be applied to subjects or functions. The most important kinds of application are:

@@ -176,17 +179,17 @@
-

The four roles (subject, function, two kinds of modifier) describe expressions, not values. When an expression is evaluated, the value's type doesn't have to correspond to its role, and can even change from one evaluation to another. An expression's role is determined entirely by its source code, so it's fixed.

-

Assignment arrows , , and store expression results in variables: and create new variables while modifies existing ones. The general format is Name Value, where the two sides have the same role. Additionally, lhs F rhs is a shortened form of lhs lhs F rhs and lhs F expands to lhs F lhs.

-

The double arrow is used for functionality relating to namespaces. It has a few purposes: exporting assignment namevalue, plain export name, and aliasing aliasfieldnamespace. A block that uses it for export returns a namespace rather than the result of its last statement.

+

The four roles (subject, function, two kinds of modifier) describe expressions, not values. When an expression is evaluated, the value's type doesn't have to correspond to its role, and can even change from one evaluation to another. An expression's role is determined entirely by its source code, so it's fixed.

+

Assignment arrows , , and store expression results in variables: and create new variables while modifies existing ones. The general format is Name Value, where the two sides have the same role. Additionally, lhs F rhs is a shortened form of lhs lhs F rhs and lhs F expands to lhs F lhs.

+

The double arrow is used for functionality relating to namespaces. It has a few purposes: exporting assignment namevalue, plain export name, and aliasing aliasfieldnamespace. A block that uses it for export returns a namespace rather than the result of its last statement. The other namespace-related bit of syntax is field access ns.field.

Lists and blocks

+

Lists and code blocks can both be represented as sequences of expressions in source code. They both have paired bracket representations, using ⟨⟩ for lists and {} for blocks, as well as a shortcut "stranding" notation using for lists.

Separators

-

The characters and , and newline are completely interchangeable and are used to separate expressions. An expression might be an element in a list or a line in a function. Empty sections—those that consist only of whitespace—are ignored. This means that any number of separators can be used between expressions, and that leading and trailing separators are also allowed. The expressions are evaluated in text order: left to right and top to bottom.

+

The characters and , and newline are completely interchangeable and are used to separate expressions. An expression might be an element in a list or a line in a block. Empty sections—those that consist only of whitespace—are ignored. This means that any number of separators can be used between expressions, and that leading and trailing separators are also allowed. The expressions are evaluated in text order: left to right and top to bottom.

List notation

Full documentation

-

Lists (1-dimensional arrays) are enclosed in angle brackets ⟨⟩, with the results of the expressions in between being the list's elements. Lists of two elements or more can also be written with the ligature character . This character has higher binding strength than any part of an expression. If one of the elements is a compound expression, then it will need to be enclosed in parentheses.

+

Lists (1-dimensional arrays) are enclosed in angle brackets ⟨⟩, with the results of the expressions in between being the list's elements. Lists of two elements or more can also be written with the ligature character . This character has higher binding strength than any part of an expression except . for namespace field access. If one of the elements is a compound expression, then it will need to be enclosed in parentheses.

Blocks

Full documentation

-

Blocks are written with curly braces {} and can be used to group expressions or define functions and modifiers. The contents are simply a sequence of expressions, where each is evaluated and the result of the last is returned in order to evaluate the block. This result can have any value, and its syntactic role in the calling context is determined by the normal rules: functions return subjects and modifiers return functions. Blocks have lexical scope.

-

The special names 𝕨 and 𝕩, which stand for arguments, and 𝕗 and 𝕘, which stand for operands, are available inside curly braces. Like ordinary names, the lowercase forms indicate subjects and the uppercase forms 𝕎𝕏𝔽𝔾 indicate functions. The type and syntactic role of the block is determined by its contents: a 2-modifier contains 𝕘, a 1-modifier contains 𝕗 but not 𝕘, and a function contains neither but does have one of 𝕨𝕩𝕤𝕎𝕏𝕊. If no special names are present the block is an immediate block and is evaluated as soon as it appears, with the result having a subject role.

-

A modifier can be evaluated twice: once when passed operands and again when the resulting function is passed arguments. If it contains 𝕨 or 𝕩, the first evaluation simply remembers the operands, and the contents will be executed only on the second evaluation, when the arguments are available. If it doesn't contain these, then the contents are executed on the first evaluation and the result is treated as a function.

+

Blocks are written with curly braces {} and can have a subject, function, or modifier role. The contents are any number of bodies separated by ;. Each body is a sequence of expressions to be evaluated in order, possibly with a header, followed by :, that sets the type and describes expected inputs. A body runs in its own environment according to the rules of lexical scoping. The result is either a namespace, if the body used , or the result of the last expression.

+

The special names 𝕨 and 𝕩, which stand for arguments, and 𝕗 and 𝕘, which stand for operands, are available inside curly braces. Like ordinary names, the lowercase forms indicate subjects and the uppercase forms 𝕎𝕏𝔽𝔾 indicate functions. If it has no header, the type and syntactic role of the block is determined by its contents: a 2-modifier contains 𝕘, a 1-modifier contains 𝕗 but not 𝕘, and a function contains neither but does have one of 𝕨𝕩𝕤𝕎𝕏𝕊. The last option is an immediate block, which has a subject role and runs as soon as it's encountered.

diff --git a/docs/doc/types.html b/docs/doc/types.html index c27a9400..430aae1e 100644 --- a/docs/doc/types.html +++ b/docs/doc/types.html @@ -57,13 +57,13 @@

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.

Arrays

-

Full documentation here.

+

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.

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.

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

+

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.

Functions

@@ -71,5 +71,5 @@

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

-

Full documentation here.

+

Full documentation.

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.

-- cgit v1.2.3