---
title: Language overview
description: The main ideas of BPL, with examples
---
BPL code consists of values, functions that apply to them, and operators that make new functions. Code is grouped by spaces and read from right to left. Each term below links to its definition in [Terms](terms.md). The exact rules are in [Syntax](syntax.md) and [Evaluation](evaluation.md), with the reasons for them in [Language principles](principles.md).

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Values

Every value is an [atom](terms.md#term-atom) or an [array](terms.md#term-array). Numbers, characters, functions and operators are atoms. An array is a rectangular collection of values laid out along axes. Here's a matrix with two rows and three columns:

```bpl
m←[1 2 3
   4 5 6]
m
```

```output
1 2 3
4 5 6
```

Shape [`ρ`](https://bpl.fast.ai//glyphs/rho.html) gives the length of each axis. The number of axes is the array's [rank](terms.md#term-rank):

```bpl
ρm
```

```output
[2 3]ₓ
```

A vector has one axis:

```bpl
ρ[10 20 30]
```

```output
[3]ₓ
```

The items of an array can be arrays themselves. Depth [`≡`](https://bpl.fast.ai//glyphs/equal-underbar.html) counts the layers of nesting. A number has none:

```bpl
≡5
```

```output
0ₓ
```

[`⊂`](https://bpl.fast.ai//glyphs/left-shoe.html) encloses a value in a [scalar](terms.md#term-scalar), an array with no axes. Enclosing always adds a layer, even around a number:

```bpl
≡⊂5
```

```output
1ₓ
```

[Arrays](arrays.md) covers shape, nesting and fill in depth.

## Writing arrays

Brackets are used to write vectors. Each item can be any expression without spaces:

```bpl
[1 2+3 "hi"]
```

```output
1 5 "hi"
```

A one-item vector is still a vector:

```bpl
ρ[5]
```

```output
[1]ₓ
```

Literals separated by spaces form a [strand](terms.md#term-strand), a vector written without brackets:

```bpl
[1 2 3]≡1 2 3
```

```output
$t
```

Inside brackets, a space always separates items. To write an item that contains spaces, separate the items with `;` instead:

```bpl
[1+2;3 4]
```

```output
[3 [3 4]]
```

Inside brackets, rows are separated by a line break or [`◇`](https://bpl.fast.ai//glyphs/diamond.html), as in the matrix `m` above. [Types of brackets](bracket-types.md) covers brackets, parentheses and braces.

## Reading an expression

Each function takes everything to its right as its right argument, with no precedence between functions. In `2×3+4`, [`×`](https://bpl.fast.ai//glyphs/times.html) multiplies 2 by the whole sum:

```bpl
2×3+4
```

```output
14
```

Subtraction follows the same rule. `10-3-2` subtracts `3-2` from 10:

```bpl
10-3-2
```

```output
9
```

Spaces group code. A [run](terms.md#term-run) is a stretch of code with no spaces in it. BPL evaluates each run first, then combines the results from right to left. Here the runs are `2×3`, [`+`](https://bpl.fast.ai//glyphs/plus.html) and `4`:

```bpl
2×3 + 4
```

```output
10
```

A function gets one argument or two depending on the value to its left when it runs. With a number on its left, `f` subtracts:

```bpl
f←-
5 f 3
```

```output
2
```

[Subjects](terms.md#term-subject) side by side form a strand, as literals do:

```bpl
a←1 2
b←3 4
a b
```

```output
(1 2◇3 4)
```

## Functions, operators and trains

An operator makes a new function from a function or an array. It takes the whole function to its left and one [token](terms.md#term-token) to its right. [`/`](https://bpl.fast.ai//glyphs/slash.html) puts its function between the items:

```bpl
+/1 2 3
```

```output
6
```

Each [`¨`](https://bpl.fast.ai//glyphs/diaeresis.html) applies its function to every item. Here Tally [`≢`](https://bpl.fast.ai//glyphs/equal-underbar-slash.html) counts the characters of each string:

```bpl
≢¨"ab" "cde"
```

```output
[2 3]ₓ
```

A run that ends in a function has no argument. The run is then a function itself, called a [train](terms.md#term-train). Three functions in a row form a [fork](terms.md#term-fork). The fork `+/÷≢` divides the sum by the count:

```bpl
mean←+/÷≢
mean 1 2 3 6
```

```output
3
```

A value directly before a function [binds](terms.md#term-bind) to it as its left argument. `2×` is the function that doubles:

```bpl
double←2×
double 5
```

```output
10
```

A space before the argument keeps a train separate from it:

```bpl
x←1 2 3 6
+/÷≢ x
```

```output
3
```

Without the space, `+/` sums a single number, the reciprocal of `≢x`:

```bpl
+/÷≢x
```

```output
0ₓ
```

## Applying functions to arrays

Arithmetic and comparison are [pervasive](terms.md#term-pervasive-function). They apply to each atom in their arguments, through any nesting. A single number is paired with every item:

```bpl
1 2 3+10
```

```output
11 12 13
```

When two arguments have different shapes, BPL lines up their leading axes. An axis of length 1 is stretched to match. Adding a two-item vector to the two-row matrix `m` adds one number to each row:

```bpl
m+10 20
```

```output
11 12 13
24 25 26
```

[`⍤`](https://bpl.fast.ai//glyphs/jot-diaeresis.html) applies a function to [cells](terms.md#term-cell) of a chosen rank. Numeric superscripts are its short spelling: `mean¹` is `mean⍤1`. The 1-cells of a matrix are its rows:

```bpl
mean¹ m
```

```output
2 5
```

Axis [`⍠`](https://bpl.fast.ai//glyphs/quad-colon.html) applies a function along chosen axes. Summing along axis 0 adds down each column:

```bpl
+/⍠0 m
```

```output
5 7 9
```

## Selecting

Positions count from 0. Index [`⌷`](https://bpl.fast.ai//glyphs/squad.html) selects along the leading axis:

```bpl
v←10 20 30
1⌷v
```

```output
20
```

Negative positions count from the end:

```bpl
¯1⌷v
```

```output
30
```

A literal position can also be written as a subscript:

```bpl
v₁
```

```output
20
```

A dot selects an entry of a [record](terms.md#term-record) by its key:

```bpl
T←["a":1 "b":2]
T.b
```

```output
2
```

## Assigning and defining

[`←`](https://bpl.fast.ai//glyphs/left-arrow.html) assigns to the run just before it, whether that's a name or a selection:

```bpl
v₁←7
v
```

```output
10 7 30
```

Braces define a function, called a [dfn](dfns.md). Inside a dfn, [`ω`](https://bpl.fast.ai//glyphs/omega.html) is the right argument and [`α`](https://bpl.fast.ai//glyphs/alpha.html) is the left argument:

```bpl
sq←{ω×ω}
sq 4
```

```output
16
```

A dfn can hold alternatives separated by `;`, each guarded by a condition ending in [`?`](https://bpl.fast.ai//glyphs/question.html). It returns the first alternative whose condition holds. You can leave out the last alternative's condition, which makes it the fallback:

```bpl
abs←{ω<0?-ω;ω}
abs ¯3
```

```output
3
```

[Assignment](assignment.md), [Dfns](dfns.md) and [Modules](modules.md) cover these in full.
