From 2db444439b7dc3662fd006b56ae88b73d7eb4e4f Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sun, 24 Jan 2021 21:25:06 -0500 Subject: BQN-J dictionary --- README.md | 2 +- doc/README.md | 1 + doc/fromJ.md | 143 +++++++++++++ docs/doc/fromJ.html | 568 ++++++++++++++++++++++++++++++++++++++++++++++++++++ docs/doc/index.html | 1 + docs/index.html | 2 +- 6 files changed, 715 insertions(+), 2 deletions(-) create mode 100644 doc/fromJ.md create mode 100644 docs/doc/fromJ.html diff --git a/README.md b/README.md index 77fff34d..35b1ecc6 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ The [font comparison page](https://mlochbaum.github.io/BQN/fonts.html) shows sev BQN's [**tutorials**](tutorial/README.md) are intended as an introduction to array programming with BQN. They assume only knowledge of elementary mathematics, but will probably be hard to follow if you have *no* programming experience. BQN has a lot in common with dynamically-typed functional languages like Lisp, Julia, or Javascript, so knowledge of these languages will be particularly helpful. However, there's a significant (but shrinking) gap between the last tutorial and existing documentation. If you're motivated, you may be able to get across by reading material on other array languages like APL, J, NumPy, or Julia. -If you're already an array programmer, then you're in better shape: the current [**documentation**](doc/README.md) covers nearly all differences from APL, and the BQN-Dyalog APL [dictionary](doc/fromDyalog.md) might also be a useful resource. However, you should be aware of two key differences between BQN and existing array languages beyond just the changes of [primitives](doc/primitive.md)—if these differences don't seem important to you then you don't understand them! BQN's [based array model](doc/based.md) is different from both a flat array model like J and a nested one like APL2, Dyalog, or GNU APL in that it has true non-array values (plain numbers and characters) that are different from depth-0 scalars. BQN also uses [syntactic roles](doc/context.md) rather than dynamic type to determine how values interact, that is, what's an argument or operand and so on. This system, along with lexical closures, means BQN fully supports Lisp-style [functional programming](doc/functional.md). +If you're already an array programmer, then you're in better shape: the current [**documentation**](doc/README.md) covers nearly all differences from APL, and the [BQN-Dyalog APL](doc/fromDyalog.md) or [BQN-J](doc/fromJ.md) dictionary might also be a useful resource. However, you should be aware of two key differences between BQN and existing array languages beyond just the changes of [primitives](doc/primitive.md)—if these differences don't seem important to you then you don't understand them! BQN's [based array model](doc/based.md) is different from both a flat array model like J and a nested one like APL2, Dyalog, or GNU APL in that it has true non-array values (plain numbers and characters) that are different from depth-0 scalars. BQN also uses [syntactic roles](doc/context.md) rather than dynamic type to determine how values interact, that is, what's an argument or operand and so on. This system, along with lexical closures, means BQN fully supports Lisp-style [functional programming](doc/functional.md). A useful tool for both beginners and experienced users is [**BQNcrate**](https://mlochbaum.github.io/bqncrate/), a searchable collection of BQN snippets to solve particular tasks. If you have a question about how you might approach a problem, give it a try by typing in a relevant keyword or two. diff --git a/doc/README.md b/doc/README.md index 046651b4..3a766abf 100644 --- a/doc/README.md +++ b/doc/README.md @@ -34,6 +34,7 @@ Primitives: References: - [Glossary](glossary.md) - [BQN-Dyalog dictionary](fromDyalog.md) +- [BQN-J dictionary](fromJ.md) Speculation: - [Possible language extensions](extensions.md) diff --git a/doc/fromJ.md b/doc/fromJ.md new file mode 100644 index 00000000..53565405 --- /dev/null +++ b/doc/fromJ.md @@ -0,0 +1,143 @@ +*View this file with results and syntax highlighting [here](https://mlochbaum.github.io/BQN/doc/fromJ.html).* + +# BQN–J dictionary + + + +A guide to help users of J get up to speed with BQN quickly. + +## Terminology + +### Array model + +BQN uses the [based array model](based.md), 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. + +BQN uses "[depth](depth.md)" 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](context.md). + +| J part of speech | BQN role | +|---------------------|------------| +| Noun | Subject | +| Verb | Function | +| Adverb | 1-modifier | +| Conjunction | 2-modifier | + +## Syntax + +| J | BQN | Remarks +|-------------------|-------------|--------- +| `NB.` | `#` | +| `'` | `"` | `'` creates characters +| `=.` and `=:` | `←` and `↩` | `←` to define; `↩` to modify +| `3 :…` or `{{…}}` | `;` | To separate function cases +| `:` | `{…}` | +| `x` `y` | `𝕨` `𝕩` | `𝕊` for block function self-reference +| `u` `v` | `𝔽` `𝔾` | `𝕣` for block modifier self-reference +| `_` | `¯` or `∞` | +| `2 3 4` | `2‿3‿4` | +| `[:` | `·` | Cap +| `assert.` | `!` | + +BQN's explicit functions and modifiers are called "blocks", and have a more sophisticated syntax than J; see [the documentation](block.md). BQN uses lexical scope, and has no global variables. BQN also has a [list notation](syntax.md#list-notation) using `⟨⟩`. + +## 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. + +| BQN | `×` | `÷` | `⋆` | `√` | `⌊` | `⌈` | `≤` | `≥` | `⊣` | `⊢` | `⌽` | `⍉` | +|:---:|:---:|:---:|:---:|:----:|:----:|:----:|:----:|:----:|:---:|:---:|:-----:|:-----:| +| J | `*` | `%` | `^` | `%:` | `<.` | `>.` | `<:` | `>:` | `[` | `]` | `\|.` | `\|:` | + +| BQN | `∧` | `∨` | `¬` | `=` | `≠` | `≡` | `≢` | `⥊` | `∾` | `≍` | +|:-----:|:-----:|:-----:|:-----:|:-----:|:----:|:----:|:-------:|:---:|:---:|:----:| +| Monad | `/:~` | `\:~` | `-.` | `#@$` | `#` | `L.` | `$` | `,` | `;` | `,:` | +| Dyad | `*.` | `+.` | `+-.` | `=` | `~:` | `-:` | `-.@-:` | `$` | `,` | `,:` | + +| BQN | `↑` | `↓` | `↕` | `»` | `«` | `/` | +|:-----:|:----:|:-----:|:----:|:--------------:|:---------------:|:----:| +| Monad | `<\` | `<\.` | `i.` | `#{.(_1-#){.]` | `-@#{.(1+#){.]` | `I.` | +| Dyad | `{.` | `}.` | `<\` | `#@]{.,` | `-@#@]{.,~` | `#` | + +| BQN | `⍋` | `⍒` | `⊏` | `⊑` | `⊐` | `⊒` | `∊` | `⍷` | `⊔` | +|:-----:|:----:|:-------:|:----:|:-------:|:-------:|:---:|:----:|:----:|:---------:| +| Monad | `/:` | `/:` | `{.` | `0{::,` | `i.~~.` | `…` | `~:` | `~.` | `` | `&.>/` | `&.>/` | `/` | `/\` | `"_1` | `"` | `L:` | `^:` | `^:_1` | + +## For writing + +J's primitive nouns are easily defined in BQN. + +| J | BQN | +|------|----------| +| `a.` | `@+↕256` | +| `a:` | `<↕0` | + +Functions `+` `-` `|` `<` `>` are the same in both languages. + +Some other primitives are essentially the same in J and BQN, but with different spellings (but [transpose](transpose.md) behaves differently; J's dyadic `|:` is more like `⍉⁼`): + +| J | `*` | `%` | `^` | `^.` | `%:` | `<.` | `>.` | `[` | `]` | `\|.` | `\|:` | +|:---:|:---:|:---:|:---:|:----:|:----:|:----:|:----:|:---:|:---:|:-----:|:-----:| +| BQN | `×` | `÷` | `⋆` | `⋆⁼` | `√` | `⌊` | `⌈` | `⊣` | `⊢` | `⌽` | `⍉` | + +Additionally, `|.!.f` is `⥊⟜f⊸«` with a natural number left argument. Change `«` to `»` to rotate right instead of left. + +The tables below give approximate implementations of J primitives. J has a whole lot of complicated primitives that no one uses (some of which are officially deprecated), so not everything is translated here. + +| J | Monad | Dyad +|------|-------------------------|----- +| `=` | `⍷⊸(≡⌜)` | `=` +| `<:` | `-⟜1` | `≤` +| `>:` | `1⊸+` | `≥` +| `+.` | | `∨` +| `+:` | `2⊸×` | `¬∨` +| `*:` | `ט` | `¬∧` +| `-.` | `¬` | `¬∘∊/⊣` +| `-:` | `÷⟜2` | `≡` +| `%.` | | `+˝∘×⎉1‿∞⁼` +| `$` | `≢` | `⥊` +| `~.` | `⍷` | +| `~:` | `∊` | `≠` +| `,` | `⥊` | `∾` +| `,.` | `⥊˘` | `∾˘` +| `,:` | `≍` | +| `;` | `∾` | `∾⟜(<⍟(1≥≡))` +| `#` | `≠` | `/` +| `#.` | `+˜⊸+˜´∘⌽` | +| `#:` | `⌽2\|⌊∘÷⟜2⍟(↕1+·⌊2⋆⁼⊢)` | ``{𝕨\|1↓⌊∘÷`⌾⌽𝕨∾<𝕩}`` +| `!` | `×´1+↕` | `-˜(+÷○(×´)⊢)1+↕∘⊣` +| `/:` | `⍋` | `⍋⊸⊏` +| `\:` | `⍒` | `⍒⊸⊏` +| `{` | `(<⟨⟩)<⊸∾⌜´⊢` | `⊏` +| `{.` | `⊏` | `↑` +| `{:` | `⊢˝` | +| `{::`| | `⊑` +| `}.` | `1⊸↓` | `↓` +| `}:` | `¯1⊸↓` | +| `e.` | `><∘∾∊¨⊢` | `∊` +| `E.` | | `⍷` +| `i.` | `↕` | `⊐` +| `i:` | `{𝕩-˜↕1+2×𝕩}` | `≠∘⊣-1+⌽⊸⊐` +| `I.` | `/` | `⍋` +| `L.` | `≡` | diff --git a/docs/doc/fromJ.html b/docs/doc/fromJ.html new file mode 100644 index 00000000..72d4f59b --- /dev/null +++ b/docs/doc/fromJ.html @@ -0,0 +1,568 @@ + + + + BQN–J dictionary + + +

BQN–J dictionary

+ +

A guide to help users of J get up to speed with BQN quickly.

+

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.

+

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.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
J part of speechBQN role
NounSubject
VerbFunction
Adverb1-modifier
Conjunction2-modifier
+

Syntax

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
JBQNRemarks
NB.#
'"' creates characters
=. and =: and to define; to modify
3 :… or {{}};To separate function cases
:{}
x y𝕨 𝕩𝕊 for block function self-reference
u v𝔽 𝔾𝕣 for block modifier self-reference
_¯ or
2 3 4234
[:·Cap
assert.!
+

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

+

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.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
BQN×÷
J*%^%:<.>.<:>:[]|.|:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
BQN¬=
Monad/:~\:~-.#@$#L.$,;,:
Dyad*.+.+-.=~:-:-.@-:$,,:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
BQN»«/
Monad<\<\.i.#{.(_1-#){.]-@#{.(1+#){.]I.
Dyad{.}.<\#@]{.,-@#@]{.,~#
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
BQN
Monad/:/:{.0{::,i.~~.~:~.</.i.@#
DyadI.I.&:-{{::i.e.E.</.
+

Most of BQN's combinators have J equivalents. The J equivalent "_ for ˙ assumes a noun operand, but ˙ makes a constant function for any operand. has arguments reversed relative to @., and uses an actual array of functions rather than gerunds. Besides these, BQN's is like a J hook, that is, FG is (F G), and applies in the opposite direction.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
BQN˙˜
J"_~@:&:&.::@.
+

For other modifiers the correspondence is looser. Here shows the dyadic case and ´ the monadic case only.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
BQN¨´˝`˘
J&.>&.>/&.>///\"_1"L:^:^:_1
+

For writing

+

J's primitive nouns are easily defined in BQN.

+ + + + + + + + + + + + + + + + + +
JBQN
a.@+↕256
a:<↕0
+

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

+

Some other primitives are essentially the same in J and BQN, but with different spellings (but transpose behaves differently; J's dyadic |: is more like ):

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
J*%^^.%:<.>.[]|.|:
BQN×÷
+

Additionally, |.!.f is f« with a natural number left argument. Change « to » to rotate right instead of left.

+

The tables below give approximate implementations of J primitives. J has a whole lot of complicated primitives that no one uses (some of which are officially deprecated), so not everything is translated here.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
JMonadDyad
=()=
<:-1
>:1+
+.
+:2׬∨
*:ט¬∧
-.¬¬∊/⊣
-:÷2
%.+˝×1
$
~.
~:
,
,.˘˘
,:
;(<(1≥≡))
#/
#.+˜+˜´
#:2|⌊÷2(1+·2){𝕨|1↓⌊÷`𝕨∾<𝕩}
!×´1+↕-˜((×´))1+↕
/:
\:
{(<⟨⟩)<⌜´
{.
{:˝
{::
}.1
}:¯1
e.><∾∊¨
E.
i.
i:{𝕩-˜1+2×𝕩}⊣-1+⌽
I./
L.
diff --git a/docs/doc/index.html b/docs/doc/index.html index 72e9568a..898d2793 100644 --- a/docs/doc/index.html +++ b/docs/doc/index.html @@ -40,6 +40,7 @@

Speculation: