*View this file with results and syntax highlighting [here](https://mlochbaum.github.io/BQN/doc/fromDyalog.html).* # BQN–Dyalog APL dictionary A few tables to help users of Dyalog APL (or similar) get started quickly on BQN. For a higher-level comparison, check [Why BQN?](../commentary/why.md#versus-apl-and-j). Here we assume `βŽ•ML` is 1 for Dyalog. ## Terminology ### Array model BQN uses the [based array model](based.md), so that a Dyalog simple scalar corresponds to many BQN values: an atom, its enclose, and so on. | Dyalog | BQN | |---------------|-------| | Simple scalar | Atom | | Scalar | Unit | | Vector | List | | Matrix | Table | BQN shares the terms "[cell](array.md#cells)" 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](context.md). | Dyalog type | BQN role | |------------------|------------| | Array | Subject | | Function | Function | | Monadic operator | 1-modifier | | Dyadic operator | 2-modifier | | Niladic function | *go away* | ## Syntax BQN comments are written with `#`, not `⍝`. BQN strings use double quotes `""` while single quotes `''` enclose a character. BQN's [block](block.md) functions use `{}`, like Dyalog's dfns. The names for inputs and self-reference are different: | Dyalog | BQN | |--------|-----| | `⍺` | `𝕨` | | `⍡` | `𝕩` | | `βˆ‡` | `π•Š` | | `⍺⍺` | `𝔽` | | `⍡⍡` | `𝔾` | | `βˆ‡βˆ‡` | `𝕣` | Blocks don't have guards exactly, but headers and predicates support some similar functionality (first-class functions can also be used for [control structures](control.md)). 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](arrayrepr.md#brackets) using `⟨⟩`, and `[]` for higher-rank arrays. ## For reading Glyphs `+-Γ—Γ·βŒŠβŒˆ|βŠ£βŠ’β‰` have nearly the same meaning in BQN as APL. The other primitive functions (except `!`, Assert) are translated loosely to Dyalog APL below. | BQN | Monad | Dyad |-----|---------------|----- | `⋆` | `*` | `*` | `√` | `*∘(Γ·2)` | `*∘÷⍨` | `∧` | `{⍡[⍋⍡]}` | `∧` | `∨` | `{⍡[⍒⍡]}` | `∨` | `Β¬` | `~` | `1+-` | `=` | `≒⍀⍴` | `=` | `β‰ ` | `β‰’` | `β‰ ` | `<` | `βŠ‚` | `<` | `>` | `↑` | `>` | `β‰’` | `⍴` | `β‰’` | `β₯Š` | `,` | `⍴` | `∾` | `βŠƒ,⌿` | `βͺ` | `≍` | `↑,β₯βŠ‚` | `↑,β₯βŠ‚` | `β‹ˆ` | `,β₯βŠ‚` | `,β₯βŠ‚` | `↑` | `,⍀` | `↑` | `↓` | `{⌽,β¨β€βŒ½β΅}` | `↓` | `↕` | `⍳` | `,⌿` | `Β»` | ` ≒↑(Β―1-β‰’)β†‘βŠ’` | ` β‰’β€βŠ’β†‘βͺ` | `Β«` | `-⍀≒↑(1+β‰’)β†‘βŠ’` | `-β€β‰’β€βŠ’β†‘βͺ⍨` | `⌽` | `βŠ–` | `βŠ–` | `/` | `⍸` | `⌿` | `⍋` | `⍋` | `⍸` | `⍒` | `⍒` | `⍸`, reversed order | `⊏` | `⊣⌿` | `⌷` | `βŠ‘` | `βŠƒ` | `βŠƒ` | `⊐` | `βˆͺ⍳⊒` | `⍳` | `βŠ’` | `+⌿∘.β‰‘β¨βˆ§βˆ˜.<⍨∘(⍳≒)` | `{Rβ†β‰’β€βŠ’β΄βˆ˜β‹βˆ˜β‹βΊβ³βͺ⍨⋄⍺(R⍨⍳R)⍡}` | `∊` | `β‰ ` | `∊` | `⍷` | `βˆͺ` | `⍷` | `βŠ”` | `{βŠ‚β΅}⌸` | `{βŠ‚β΅}⌸` or `βŠ†` Modifiers are a little harder. Many have equivalents in some cases, but Dyalog sometimes chooses different functionality based on whether the operand is an array. In BQN an array is always treated as a constant function. | BQN | `Β¨` | `⌜` | `˝` | `` ` `` | `βŽ‰` | `⍟` | `˜` | `∘` | `β—‹` | `⟜` | |:------:|:---:|:----:|:---:|:-------:|:----:|:---:|:---:|:----:|:---:|:---:| | Dyalog | `Β¨` | `∘.` | `⌿` | `⍀` | `⍀A` | `⍣` | `⍨` | `⍀f` | `β₯` | `∘` | Some other BQN modifiers have been proposed as future Dyalog extensions: | BQN | `⌾` | `βš‡` | `⊸` | |:---------------:|:---:|:---:|:---:| | Dyalog proposed | `⍒` [Under](https://aplwiki.com/wiki/Under) | `β₯` [Depth](https://aplwiki.com/wiki/Depth_(operator)) | `⍛` [Reverse Compose](https://aplwiki.com/wiki/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 `F⍣G` (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](control.md#low-stack-version) and called as `Fn _while_ Cond arg`.
Functions
Glyph Monadic Dyadic
* ⋆
⍟ ⋆⁼
! Γ—Β΄1+↕ (-Γ·β—‹(Γ—Β΄)1⊸+)βŸœβ†•Λœ
β—‹ Ο€βŠΈΓ— β€’math
~ ¬ ¬∘∊/⊣
? β€’rand.Rangeβš‡0 β€’rand.Deal
⍲ ¬∘∧
⍱ ¬∘∨
⍴ β‰’ β₯Š
, β₯Š βˆΎβŽ‰1
βͺ β₯ŠΛ˜ ∾
⌽ βŒ½βŽ‰0β€Ώ1
↑ > ↑
↓ <˘ ↓
βŠ‚ < +`βŠΈβŠ”
βŠ† <⍟(1β‰₯≑) (Β¬-ΛœβŠ’Γ—Β·+`»⊸>)βŠΈβŠ”
∊ {(βˆΎπ•ŠΒ¨)⍟(1<≑)β₯Šπ•©} ∊
βŠƒ βŠ‘
⌿ /
⍀ {π•©βŒΎ(π•¨βŠΈ/)π•¨β‰ βŠΈβ†‘0↑𝕩}
∩ ∊/⊣
βˆͺ ⍷ ⊣∾∊˜¬⊸/⊒
⍳ ↕ ⊐
⍸ / ⍋
⍋ ⍋ β‹βŠ
⍒ ⍒ β’βŠ
β‰’ β‰  β‰’
⍎ β€’BQN
⍕ β€’Fmt
βŠ₯ {+⟜(π•¨βŠΈΓ—)Β΄βŒ½π•©}
⊀ {𝕨|>⌊∘÷`βŒΎβŒ½π•¨Β«Λœ<𝕩}
⌹ Inverse, Solve from here
⌷ N/A ⊏
Operators
Syntax Monadic Dyadic
⌿ ¨˝ ↕
⍀ ↑, or ` if associative
Β¨ Β¨
⍨ ˜
⍣ ⍟
f.g f˝∘gβŽ‰1β€Ώβˆž
∘.f f⌜
A∘g A⊸g
f∘B f⟜B
f∘g f⟜g
f⍀B fβŽ‰B
f⍀g f∘g
fβ₯g fβ—‹g
f@v f⌾(v⊸⊏)
f⍠B Uh
f⌸ βŠβŠ”β†•βˆ˜β‰ βŠβŠΈβŠ”
f⌺B ↕
A⌢ β€’Something
f& Nothing yet