Algol 68 modes
last modified November 13, 2026
A mode is an Algol 68 type. Modes describe both the values a program works with and the layout of those values in memory. This article introduces the primitive modes, then shows how rows, structures, and user-defined modes are built from them.
What a mode is
The primitive modes are INT, REAL,
COMPL for complex numbers, BOOL, CHAR,
BITS, BYTES, and VOID. Transput adds
FILE, FORMAT, and CHANNEL. The prefixes
LONG and SHORT adjust the precision of numeric
modes, so LONG INT and SHORT REAL are modes in their
own right.
STRING is not primitive: it abbreviates a flexible row of
characters. Rows are written with bounds in square brackets, as in
[]INT for a row of integers. A structure groups named fields, a
union holds one of several modes, and a reference names a value stored
elsewhere. A MODE declaration introduces a new name for any of
these.
Integers
INT holds a signed integer. The operators +,
-, and * behave as expected, **
raises a number to a power, OVER performs integer division, and
MOD gives the remainder.
BEGIN INT a = 7, b = 2; print((whole(a + b, 0), " ", whole(a - b, 0), " ", whole(a * b, 0), newline)); print((whole(a OVER b, 0), " ", whole(a MOD b, 0), " ", whole(a ** b, 0), newline)) END
Integer division truncates toward zero and discards the remainder, which
MOD recovers. A declaration may list several names of the same
mode, as in INT a = 7, b = 2. The division operator
/ is different: it produces a real even when both operands are
integers.
$ a68g ints.a68 9 5 14 3 1 49
Reals
REAL holds a floating-point number. A real denotation contains a
decimal point or an exponent, and an integer is widened to a real
automatically when the context requires one. fixed rounds a real
to a given number of decimal places and returns a string.
BEGIN REAL sum = 1.5 + 2.25; REAL third = 1.0 / 3.0; print((fixed(sum, 0, 2), " ", fixed(third, 0, 4), newline)) END
The second argument of fixed is the minimum field width and the
third is the number of digits after the decimal point. A width of 0 means
that the string is only as wide as necessary, which is why
fixed(third, 0, 4) prints .3333 without a leading
zero.
$ a68g reals.a68 3.75 .3333
Booleans and characters
BOOL has the values TRUE and FALSE.
CHAR holds one character, written as a one-character string in
double quotes. The operator ABS converts a character to its
integer code, REPR converts an integer back to a character, and
ODD tests whether an integer is odd.
BEGIN BOOL ready = TRUE; CHAR letter = "A"; print((ready, " ", letter, " ", whole(ABS letter, 0), " ", REPR 66, newline)); print((ODD 7, " ", ODD 8, newline)) END
print writes a boolean as T or F.
ABS "A" is 65, and REPR 66 produces
"B". The last line shows that ODD returns a
boolean, not an integer.
$ a68g boolchar.a68 T A 65 B T F
Strings
A STRING is a flexible row of characters. Its positions are
numbered from 1, so s[1] is the first character and
s[1:5] is a slice. UPB and LWB return
the upper and lower bounds, and + concatenates two strings.
BEGIN STRING s = "Algol 68"; print((s, newline)); print((s[1], s[7], newline)); print((s[1:5], newline)); print((s + " Genie", newline)); print((whole(UPB s, 0), " ", whole(LWB s, 0), newline)) END
The string has eight characters, so its bounds are 1 and 8. Indexing with
s[7] returns the digit 6, and the slice
s[1:5] returns Algol. Concatenation produces a new
string and leaves s unchanged.
$ a68g strings.a68 Algol 68 A6 Algol Algol 68 Genie 8 1
Complex numbers
COMPL holds a complex number. A complex denotation joins the real
and imaginary parts with I. The fields re and
im are selected with OF, and ABS
returns the modulus.
BEGIN COMPL z = 3.0 I 4.0; COMPL w = z * z; print((fixed(re OF z, 0, 1), " ", fixed(im OF z, 0, 1), newline)); print((fixed(re OF w, 0, 1), " ", fixed(im OF w, 0, 1), newline)); print((fixed(ABS z, 0, 1), newline)) END
Squaring 3 + 4i gives -7 + 24i, and the modulus of
the original value is 5. The arithmetic operators work on complex values
directly; only the field selections need to be printed separately.
$ a68g complex.a68 3.0 4.0 -7.0 24.0 5.0
Bits
BITS holds a bit string. A based denotation such as
2r1100 gives a bit pattern, and the operators
AND, OR, XOR, NOT,
SHL, and SHR work on it. ABS converts
a bit pattern to an integer.
BEGIN BITS a = 2r1100, b = 2r1010; print((whole(ABS (a AND b), 0), " ", whole(ABS (a OR b), 0), newline)); print((whole(ABS (a XOR b), 0), " ", whole(ABS (a SHL 2), 0), " ", whole(ABS (b SHR 1), 0), newline)) END
a AND b keeps the common bits, a OR b combines
them, and a XOR b keeps the bits that differ.
SHL and SHR shift the pattern left and right. The
conversions with ABS are needed because whole prints
integers, not bit strings.
$ a68g bits.a68 8 14 6 48 5
Rows, structures and new modes
A row is a sequence of values of one mode. Rows with known bounds are written
with those bounds, while []INT takes its bounds from the value
that initialises it. A structure groups fields, which are selected with
OF. A MODE declaration gives a name to either.
MODE POINT = STRUCT (REAL x, REAL y); BEGIN []INT nums = (10, 20, 30); POINT p = (1.5, 2.5); print((whole(nums[2], 0), " ", whole(UPB nums, 0), newline)); print((fixed(x OF p, 0, 1), " ", fixed(y OF p, 0, 1), newline)) END
nums has three elements and its upper bound is 3. The structure
p is initialised with a row of two values, one for each field,
and the fields are read back with x OF p and
y OF p. The MODE declaration can appear before or
inside a clause.
$ a68g composite.a68 20 3 1.5 2.5
Next steps
The variables article explains how values of these modes are stored and named. The program structure article describes the clauses in which expressions and declarations appear, and Algol 68 basics puts the primitive modes to work in complete programs.
Source
Revised Report on the Algorithmic Language Algol 68
In this article we have surveyed the primitive modes and the composite modes
built from them: rows, structures, and named MODE declarations.
The variables article continues with
references and storage, and Algol 68 basics
shows the modes in small programs.
Author
List all Algol 68 tutorials.