From a25cb2b0bf26033c9bc778d816618a752d015d99 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 5 Jul 2022 16:46:42 -0400 Subject: Somehow, all the docs have now been edited --- docs/doc/fromDyalog.html | 45 +++++++++++++++++++++++---------- docs/doc/fromJ.html | 16 ++++++------ docs/doc/functional.html | 12 ++++----- docs/doc/glossary.html | 58 +++++++++++++++++++++--------------------- docs/doc/group.html | 66 +++++++++++++++++++++++++----------------------- docs/doc/map.html | 28 ++++++++++++-------- 6 files changed, 126 insertions(+), 99 deletions(-) (limited to 'docs/doc') diff --git a/docs/doc/fromDyalog.html b/docs/doc/fromDyalog.html index ea036ec9..1e36dada 100644 --- a/docs/doc/fromDyalog.html +++ b/docs/doc/fromDyalog.html @@ -35,8 +35,7 @@ -

BQN shares the terms "cell" and "major cell" with Dyalog, and uses -"element" (which may mean different things to different Dyalog users) not for a 0-cell but for the value it contains.

+

BQN shares the terms "cell" and "major cell" with Dyalog, and uses "element" (which may mean different things to different Dyalog users) not for a 0-cell but for the value it contains.

Roles

Dyalog uses value types (array, function, and so on) to determine syntax while BQN uses a separate concept called syntactic roles. See context-free grammar.

@@ -71,7 +70,7 @@

Syntax

BQN comments are written with #, not . BQN strings use double quotes "" while single quotes '' enclose a character.

-

BQN's functions use {}, like Dyalog's dfns. The names for inputs and self-reference are different:

+

BQN's block functions use {}, like Dyalog's dfns. The names for inputs and self-reference are different:

@@ -106,11 +105,11 @@
-

BQN doesn't have guards: it uses modifiers or control structures instead. However, BQN function and modifier blocks have headers that allow pattern matching. See the block documentation.

+

Blocks don't have guards exactly, but headers and predicates support some similar functionality (first-class functions can also be used for control structures). Headers can also be used to make a block more explicit about its inputs, more like a tradfn.

The assignment arrow defines a new variable in a block, while modifies an existing one.

-

BQN uses the ligature character for stranding, instead of plain juxtaposition. It also has a list notation using ⟨⟩.

+

BQN uses the ligature character for stranding, instead of plain juxtaposition. It also has a list notation using ⟨⟩, and [] for higher-rank arrays.

For reading

-

Here are some closest equivalents in Dyalog APL for the BQN functions that don't use the same glyphs as APL. Correspondence can be approximate, and is just used as a decorator to mean "reverse some things".

+

Here are some closest equivalents in Dyalog APL for the BQN functions that don't use the same glyphs. Correspondence can be approximate, and is just used as a decorator to mean "reverse some things".

@@ -265,16 +264,34 @@ - + - +
¨ . A ⍤f
-

In BQN is Rank and is Atop. Dyalog's Atop () and Over () were added in version 18.0.

+

Some other BQN modifiers have been proposed as future Dyalog extensions:

+ + + + + + + + + + + + + + + + + +
BQN
Dyalog proposed Under Depth Reverse Compose

For writing

The tables below give approximate implementations of Dyalog primitives for the ones that aren't the same. First- and last-axis pairs are also mostly omitted. BQN just has the first-axis form, and you can get the last-axis form with 1.

The form FG (Power with a function right operand; Power limit) must be implemented with recursion instead of primitives because it performs unbounded iteration. The modifier _while_ {𝔽𝔾𝔽_𝕣_𝔾𝔽𝔾𝕩} provides similar functionality without risk of stack overflow. It's discussed here and called as Fn _while_ Cond arg.

@@ -283,7 +300,7 @@ Glyph Monadic Dyadic * - ! ×´1+↕ -˜((×´))1+↕ + ! ×´1+↕ ((×´)1+)˜ π× •math ~ ¬ ¬∊/⊣ ? •rand.Range0 •rand.Deal @@ -294,10 +311,10 @@ ˘ 01 > - <˘ + <˘ < +` <(0<≡) (¬-˜⊢×·+`»>) - {(∾𝕊¨)(0<≡𝕩)𝕩} + {(∾𝕊¨)(0<≡)𝕩} {𝕩(𝕨/)𝕨0𝕩} ∊/⊣ @@ -310,8 +327,8 @@ •BQN •Fmt {+(𝕨×)´𝕩} - {>𝕨|⌊÷`𝕨«˜<𝕩} - Inverse from hereSolve + {𝕨|>⌊÷`𝕨«˜<𝕩} + Inverse, Solve from here N/A diff --git a/docs/doc/fromJ.html b/docs/doc/fromJ.html index 338a17d5..489240d8 100644 --- a/docs/doc/fromJ.html +++ b/docs/doc/fromJ.html @@ -10,10 +10,10 @@

Terminology

Array model

BQN uses the based array model, which is fundamentally different from J's flat array model. BQN uses non-array values such as characters and numbers, called "atoms", while in J every noun is an array. A BQN array can contain any values in any mixture, while a J array must be uniformly numbers, characters, or boxes (BQN doesn't use boxes).

-

The J terms "atom" and "element" are used to mean different things by different authors. In BQN, an atom or rank-0 array is called a "unit", and the values contained in an array—which may or may not be arrays—are called "elements". Each element is contained in a 0-cell, or rank-0 subarray. BQN uses the term "major cell" for what J calls an "item" of an array: a cell with rank one less than that array. BQN shares the terms "list" and "table" for rank-1 and rank-2 arrays with J.

+

The J terms "atom" and "element" are used to mean different things by different authors. In BQN, a rank-0 array or atom is called a "unit", and the values contained in an array—which may or may not be arrays—are called "elements". Each element is contained in a 0-cell, or rank-0 subarray. BQN uses the term "major cell" for what J calls an "item" of an array: a cell with rank one less than that array. BQN shares the terms "list" and "table" for rank-1 and rank-2 arrays with J.

BQN uses "depth" rather than "boxing level". BQN gives atoms depth 0, so that the depth of a BQN array is one higher than the boxing level of the corresponding J array.

Roles

-

In J, the part of speech is an inherent property of a value, while in BQN it is determined by how the value is used in a particular expression, and can be different from the value's type. See context-free grammar.

+

In J, the part of speech is an inherent property of a value, while in BQN it's determined by how the value is used in a particular expression, and can be different from the value's type. See context-free grammar.

@@ -58,7 +58,7 @@ - + @@ -107,7 +107,7 @@
' "' creates characters' for character atoms
=. and =:
-

BQN's explicit functions and modifiers are called "blocks", and have a more sophisticated syntax than J; see the documentation. BQN uses lexical scope, and has no global variables. BQN also has a list notation using ⟨⟩.

+

BQN's explicit functions and modifiers are called blocks, and have a more sophisticated syntax than J. BQN uses lexical scope, and has no global variables. BQN also has a list notation using ⟨⟩, and [] for higher-rank arrays.

For reading

J analogues of BQN primitive functions are given below. They are not always the same; usually this is because BQN has extra functionality relative to J, although in some cases it has less or different functionality.

Functions + - | < > are the same in both languages.

@@ -485,8 +485,8 @@ %. -Inverse from here -Solve +Inverse, +Solve from here $ @@ -516,7 +516,7 @@ ,: - + ; @@ -541,7 +541,7 @@ ! ×´1+↕ --˜((×´))1+↕ +((×´)1+)˜ /: diff --git a/docs/doc/functional.html b/docs/doc/functional.html index d7fbad61..ea4d18ca 100644 --- a/docs/doc/functional.html +++ b/docs/doc/functional.html @@ -6,8 +6,8 @@

Functional programming

BQN boasts of its functional capabilities, including first-class functions. What sort of functional support does it have, and how can a BQN programmer exercise these and out themself as a Schemer at heart?

-

First, let's be clear about what the terms we're using mean. A language has first-class functions when functions (however they are defined) can be used in all the same ways as "ordinary" values like numbers and so on, such as being passed as an argument or placed in a list. Lisp and JavaScript have first-class functions, C has unsafe first-class functions via function pointers, and Java 7 and APL don't have them as functions can't be placed in lists or used as arguments. This doesn't mean every operation is supported on functions: for instance, numbers can be added, compared, and sorted; while functions could perhaps be added to give a train, comparing or sorting them as functions (not representations) isn't computable, and BQN doesn't support any of the three operations when passing functions as arguments.

-

Traditionally, APL has worked around its lack of first-class functions with operators, that is, second-order functions. Arrays in APL are first class while functions are second class and operators are third class, and each class can act on the ones before it. However, the three-tier system has some obvious limitations that we'll discuss, and BQN removes these by making every type first class.

+

First, let's be clear about what the terms we're using mean. A language has first-class functions when functions (however they are defined) can be used in all the same ways as "ordinary" values like numbers and so on, such as being passed as an argument or placed in a list. Lisp and JavaScript have first-class functions, and C has unsafe first-class functions via function pointers. Java 7 and APL don't have them, as functions can't be placed in lists or used as arguments. This doesn't mean every operation is supported on functions: for instance, numbers can be added, compared, and sorted; while functions could perhaps be added to give a train, comparing or sorting them as functions (not representations) isn't computable, and BQN doesn't support any of the three operations when passing functions as arguments.

+

Traditionally, APL has worked around its lack of first-class functions with operators, that is, second-order functions. Arrays in APL are first class while functions are second class and operators are third class, and each class can act on the ones above it. However, the three-tier system has some obvious limitations that we'll discuss, and BQN removes these by making every type first class.

"Functional programming" @@ -59,8 +59,8 @@ -

The term functional programming is more contentious, and has many meanings some of which can be vague. Here I use it for what might be called first-class functional programming, programming that makes significant use of first-class functions; in this usage, Scheme is probably the archetypal functional programming language. However, other definitions are also worth mentioning. APL is often called a functional programming language on the grounds that functions can be assigned and manipulated, and called recursively, all characteristics it shares with Lisp. I prefer the term function-level programming for this usage. A newer usage, which I call pure functional programming, restricts the term "function" to mathematical functions, which have no side effects, so that functional programming is programming with no side effects, often using monads to accumulate effects as part of arguments and results instead. Finally, typed functional programming is closely associated with pure functional programming and refers to languages influenced by type theory such as Haskell, F#, and Idris (the last of which even supports dependently-typed functional programming, but I already said "finally" so we'll stop there). Of these, BQN supports first-class functional and function-level programming, allows but doesn't encourage pure functional programming, and does not support typed functional programming, as it's dynamically and not statically typed.

-

Another topic we are interested in is lexical scoping and closures. Lexical scoping means that the realm in which a variable exists is determined by its containing context (in BQN, the surrounding set of curly braces {}, if any) within the source code. A closure is really an implementation mechanism, but it's often used to refer to a property of lexical scoping that appears when functions defined in a particular block can be accessed after the block finishes execution. For example, they might be returned from a function or assigned to a variable outside of that function's scope. In this case the functions can still access variables in the original scope. I consider this property to be a requirement for a correct lexical scoping implementation, but it's traditionally not a part of APL: implementation might not have lexical scoping (for example, J and I believe A+ use static scoping where functions can't access variables in containing scopes) or might cut off the scope once execution ends, leading to value errors that one wouldn't predict from the rules of lexical scoping.

+

The term functional programming is more contentious, and has many meanings some of which can be vague. Here I use it for what might be called first-class functional programming, programming that makes significant use of first-class functions; in this usage, Scheme is probably the archetypal functional programming language. However, other definitions are also worth mentioning. APL is often called a functional programming language on the grounds that functions can be assigned and manipulated, and called recursively, all characteristics it shares with Lisp. I prefer the term function-level programming for this usage. A newer usage, which I call pure functional programming, restricts the term "function" to mathematical functions, which have no side effects, so that functional programming is programming with no side effects, often using monads to accumulate effects as part of arguments and results instead. Finally, typed functional programming is closely associated with pure functional programming and refers to languages influenced by type theory such as Haskell, F#, and Idris (the last of which even supports dependently-typed functional programming, but I already said "finally" so we'll stop there). Of these, BQN supports first-class functional and function-level programming, allows but doesn't encourage pure functional programming, and doesn't support typed functional programming, as it's dynamically and not statically typed.

+

Another topic we're interested in is lexical scoping and closures. Lexical scoping means that the realm in which a variable exists is determined by its containing context (in BQN, the surrounding set of curly braces {}, if any) within the source code. A closure is really an implementation mechanism, but it's often used to refer to a property of lexical scoping that appears when functions defined in a particular block can be accessed after the block finishes execution. For example, they might be returned from a function or assigned to a variable outside of that function's scope. In this case the functions can still access variables in the original scope. I consider this property to be a requirement for a correct lexical scoping implementation, but it's traditionally not a part of APL: implementation might not have lexical scoping (for example, J and K use static scoping where functions can't access variables in containing scopes) or might cut off the scope once execution ends, leading to value errors that one wouldn't predict from the rules of lexical scoping.

Functions in APL

This seems like a good place for a brief and entirely optional discussion of how APL handles functions and why it does it this way. As mentioned above, APL's functions are second class rather than first class. But the barriers to making functions first-class objects have been entirely syntactic and conceptual, not technical. In fact, the J language has for a long time had a bug that allows an array containing a function to be created: by selecting from the array, the function itself can even be passed through tacit functions as an argument!

The primary reason why APL doesn't allow functions to be passed as arguments is probably syntax: in particular, there's no way to say that a function should be used as the left argument to another function, as an expression like F G x with functions F and G and an array x will simply be evaluated as two monadic function applications. However, there's no syntactic rule that prevents a function from returning a function, and Dyalog APL for example allows this (so '+' returns the function +). Dyalog's OR is another interesting phenomenon in this context: it creates an array from a function or operator, which can then be used as an element or argument like any array. The mechanism is essentially the same as BQN's first class functions, and in fact ORs even share a form of BQN's syntactic type erasure, as a OR of a function passed as an operand magically becomes a function again. But outside of this property, it's cumbersome and slow to convert functions to and from ORs, so they don't work very well as a first-class function mechanism.

@@ -86,7 +86,7 @@ ExpLin 5 9.591409142295225 -

A tricker but more compact method is to use the 1-modifier {𝔽}, as the input to a modifier can have a subject or function role but its output always has a function role.

+

A tricker but more compact method is to use the 1-modifier {𝔽}, as a modifier's operand can have a subject or function role but its output always has a function role.

↗️
    (Lin exp){𝔽} 5
 9.591409142295225
 
@@ -119,7 +119,7 @@ ↗️
    , 2, ⊢-⋆ {𝕎𝕩}¨ 9
 ⟨ 3 ⟨ 2 9 ⟩ ¯8094.083927575384 ⟩
 
-

The 2-modifier Choose () relies on arrays of functions to… function. It's very closely related to Pick , and in fact when the left operand and the elements of the right operand are all data there's no real difference: Choose returns the constant function 𝕗𝕘.

+

The 2-modifier Choose () relies on arrays of functions to… function. It's very closely related to Pick , and in fact when the left operand and the elements of the right operand are all data there's no real difference: Choose results in the constant function 𝕗𝕘.

↗️
    2"abcdef" "arg"
 'c'
 
diff --git a/docs/doc/glossary.html b/docs/doc/glossary.html index 13581749..3588a8d8 100644 --- a/docs/doc/glossary.html +++ b/docs/doc/glossary.html @@ -37,34 +37,23 @@
  • Real number (more accurately, approximate doubly-extended real number): A number with no complex part.
  • Complex number: A real number plus i (one of the square roots of -1) times another real number.
  • -

    Roles

    - -

    The possible roles are:

    -

    Arrays

    -

    Namespaces

    -

    Tokens

    -

    Parsing

    +

    Grammar

    +

    Roles

    + +

    The possible roles are:

    +

    Assignment and scoping