View this file with results and syntax highlighting here.
A few tables to help users of Dyalog APL (or similar) get started quickly on BQN. For a higher-level comparison, check Why BQN?. Here we assume ⎕ML
is 1 for Dyalog.
BQN uses the based array model, 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" 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.
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.
Dyalog type | BQN role |
---|---|
Array | Subject |
Function | Function |
Monadic operator | 1-modifier |
Dyadic operator | 2-modifier |
Niladic function | go away |
BQN comments are written with #
, not ⍝
. BQN strings use double quotes ""
while single quotes ''
enclose a character.
BQN's block 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). 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 ⟨⟩
, and []
for higher-rank arrays.
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 | ¨ |
∘. |
⌿ |
⍀ |
⍤¯1 |
⍤A |
BQN | ⁼ |
⍟ |
˜ |
∘ |
○ |
⟜ |
---|---|---|---|---|---|---|
Dyalog | ⍣¯1 |
⍣ |
⍨ |
⍤f |
⍥ |
∘ |
Some other BQN modifiers have been proposed as future Dyalog extensions:
BQN | ⌾ |
⚇ |
⊸ |
---|---|---|---|
Dyalog proposed | ⍢ Under |
⍥ Depth |
⍛ Reverse Compose |
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) can't be implemented with primitives alone because it performs unbounded iteration. Typically Fn •_while_ Cond arg
should be used for this functionality. The definition _while_ ← {𝔽⍟𝔾∘𝔽_𝕣_𝔾∘𝔽⍟𝔾𝕩}
also works; it's more complicated than you might expect to avoid stack overflow, as discussed here.
Functions | ||
---|---|---|
Glyph | Monadic | Dyadic |
* | ⋆ | |
⍟ | ⋆⁼ | |
! | ×´1+↕ | (-÷○(×´)1⊸+)⟜↕˜ |
… | •math.Fact | •math.Comb˜ |
○ | π⊸× | •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 | B⊸↕ | |
A⌶ | •Something | |
f& | Nothing yet |