ALGOL 68, the basis of all modern languages

The purpose of this paper is to give an overall idea of the syntax of ALGOL 68, and to show how the language influenced its successors, including C, Pascal and all C-Like, notably Go. For a detailed knowledge of the language we refer to the manuals given in reference at the bottom of the page.

The first ALGOL 68 compiler was made in 1970 by Peck, Koster, Mailloux and Wijngaarden at the IFIP Working Group. For their part, Nicklaus Wirth and Tony Hoare had already developed in 1966 ALGOL W, another successor to ALGOL 60.
ALGOL W was the basis of the Pascal language, which also appeared in 1970 and which in fact took the place of the universal language that the authors wanted to confer on ALGOL 68. But the latter inspired all the C-Like.

Description of the ALGOL 68 language

The complexity of ALGOL 68 would make it difficult to understand for a modern programmer, which is not seen in the code below which is limited to the simplest syntax.

Types

It will be noted that very logically, a real number is represented by the real type, taken up by Pascal, whereas C uses float which is the name of the representation in memory: "floating point". And C was followed stupidly by most later languages.

The string type is also replaced in C by char *, but it will come back in C++ and in modern languages.

For numeric types, the long and short modifiers specify the number of bytes of memory representation, which is taken up by C.

Predefined values:

Operators

Most of them are found in C.

The not-equal operator is the most controversial. ALGOL 68 has several options, Pascal uses <>, C uses rather! = that is used by all C-like. ~ = reappears later in Lua.

Assignment and declaration

Assignments:

a := 10;
a := b := c := 10; // 10 assigned to a, b and c.
a +:= b; // same as a := a + b

You can replace + with any other arithmetic operator.

Declarations:

int i = 10;
real r  = 1.2;
[]int ai = (2,5,89,6,3);
[]string astr = ("a", "b", "hello");
[1:2,4:5]int mi = ((10,20), (100,200)); // Two-dimensional array.

Constant and variable

int i = 10;
int j := 20;

i is a constant while j is a variable. This has not been taken up in any other language.

Indexation and slices

[]int ai = (10,20,30,40,50);

ai[2] returns 30.

ai[2 : 3] returns 40,50.

The language has a complex syntax for accessing the contents of a multidimensional array, or a string of characters that unnecessarily complicates the making of a compiler.

Dynamic array

The flex modifier allows you to define an array as variable in size.

Structure

The declaration is similar to the header of a function.

struct (int i, real r) s;
i of s := 10;
r of s := 1.23;

The C equivalent would be:

struct s {
  int i = 10;
  real r = 1.23;
} 

Pascal choosen to use the record construct instead, from ALGOL 60, which originally came from COBOL. Both are structured types and classes ancestors.

Union

In a union, the variables share the same memory area, and the same value can be accessed with different types.

union(int i, real r) u;  

If control structure

The terminator is the word if in reverse. A strange syntax that can not be found in any other language that has succeeded, not even in Pascal.

if condition then
...
[else ... ]
fi

ou

if condition then
...
elif condition then
...
[else ...]
fi 

For control structure

It does a lot of things at once.

for variable from start [by increment] to end [while condition] do
   ...
od

Example:

for i from 1 to 10 while i ne 11 do
  ...
od

The different parts are optional. for example

to 10 do ... od 

execute the loop ten times. While:

for i while i < 11 do ... od

executes the loop as long as the condition is satisfied.

The tendency was then to divide the structure into several others: for, while, do until, for in. However the Go language has returned to this multi-purpose structure.
Foreach was later added to ALGOL 68 by some compilers.

Case control structure

The ancestor of the switch case control structure was more limited:

case variable in
instructions,
instructions,
...
esac; 

Example for the number of days in the months of a year, from January to December.
The month variable has a value from 1 to 12.

case month in
31,
if year % 4 = 0 and year % 100 ~= 0 or year % 400 = 0 then 29 else fi;
31,30,31,30,31,31,30,31,30,31
esac;

Procedure

The type of return is placed at the end of the header, unlike C and we find this in some modern languages, it comes from ALGOL.

proc p = (int a, real b) real:
begin
   ... 
end;

The parameters are in parentheses, the type of return is placed next.
The return value is the value of the last expression evaluated in the body of the procedure. An idea taken up by the language Julia.

Format of a procedure without parameters and which returns nothing:

proc q = void:
begin
   ... 
end;

Pascal has moved to complicate things by differentiating functions that return a value and procedures that do not return anything, a duality that also exists in Fortran. It is a regression and it brings nothing. Moreover, a Fortran routine can return several values at a time which Pascal misses.

Concurrency

Procedures can be executed in parallel with the command par:

par begin
  ...
end; 

Go's coroutines are pretty similar.

Conclusion

The language seems to have been defined by a discussion group where everyone wants to bring their ideas to complete the language and where nobody cares about the construction of the compiler that will implement it. This prompted Niklaus Wirth, to obtain a powerful compiler, to create Pascal on the basis of ALGOL but by getting rid of a large part of the elements of the language.

However, many of the concepts present in ALGOL are found in the languages that have followed, and some that have been abandoned reappear in recent languages like Go, Julia. Conversely, the different syntax and concepts of other ancient languages like Tcl, Rebol, etc ... have fallen into oblivion.

References:

Programming and data languages Asm.js - Basic - C - C++ - C# - Dart - Go - Java - JavaScript - Julia - Pascal - PHP - Prolog - Python - Ruby - Rust - Scala - Scriptol - Swift - TypeScript - HTML - Wasm - XML - XAML - SQL