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.

A program is a unit of source code that's evaluated, such as a source file, or one line of REPL input (one run of the bqn executable often involves multiple programs). Like a block, it's a sequence of expressions to be evaluated in order. It has a result, which is used if the program was evaluated from BQN with •BQN, •Import or similar. An error might occur when a program is running; this ends execution unless it's caught.

Precedence

Here's a full table of precedence for BQN's glyphs (broader than "operator precedence", as an "operator" usually just corresponds to a function). Entries at the bottom make the biggest divisions in the program, while the ones further up are subdivisions.

Level Role Associativity Characters Plus
High Brackets ()⟨⟩{}[]
Field access Left-to-right .
Stranding n-ary
Modifier Left-to-right ∘⎉¨´ in Fn
Function Right-to-left +↕⊔⍉ ←↩⇐
Separator ⋄, and newline ?
Header :
Low Body ;

While all of BQN's grammar fits into this table somehow, it's not really the whole story because subexpressions including parentheses and blocks might behave like functions or modifiers. See expressions and blocks.

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 variable names.

Glyph(s) Meaning
# Comment
'" Character or string literal
@ Null character
¯∞π Used in numeric literals
· Nothing
() Expression grouping
Define
Export
Change
. Namespace field access
⋄, or newline Statement or element separator
⟨⟩ List
[] Array
Strand (lightweight list syntax)
{} Block such as a function definition
: Block header
; Block body separator
? Predicate
𝕨𝕎 Left argument
𝕩𝕏 Right argument
𝕤𝕊 Function self-reference
𝕗𝔽 Left operand of a modifier
𝕘𝔾 Right operand of a 2-modifier
𝕣 Modifier self-reference

Tokens

Full documentation

BQN syntax is made up of tokens, which are mostly single characters. But there are a few exceptions:

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:

example left main right output name binding
10 w? F x Subject Function RtL, looser
+ - F? G H Function Train
×´ F _m Function 1-Modifier LtR, tighter
2| F _c_ G Function 2-Modifier

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.

Arrays and blocks

Arrays and code blocks can both be represented as sequences of expressions in source code. There are paired bracket representations, using ⟨⟩ for lists, [] for arrays, and {} for blocks, as well as a shortcut "stranding" notation using for lists. Elements within brackets are divided by separators: , or or a line break.

List and array 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 except . for namespace field access. If one of the elements is a compound expression, then it will need to be enclosed in parentheses.

Arrays, or at least non-empty ones with rank 1 or more, can be written with square brackets []. These work just like angle brackets but merge the elements so that they form cells of the result.

Blocks

Full documentation

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.