Beginner

Hello World in ALGOL 68

Your first ALGOL 68 program - the classic Hello World example with Docker setup and historical context

Introduction

Welcome to ALGOL 68! This tutorial will guide you through writing and running your first ALGOL 68 program. ALGOL 68, designed in the late 1960s, was one of the most influential programming languages in history, despite never achieving mainstream commercial adoption. Its innovative features influenced C, C++, Pascal, and even Unix shells.

What is ALGOL 68?

ALGOL 68 (Algorithmic Language 1968) was designed by IFIP Working Group 2.1 as a successor to ALGOL 60. The language introduced many concepts that were revolutionary for its time:

  • User-defined operators
  • Flexible array bounds
  • Parallel processing constructs
  • A sophisticated type system called “modes”
  • Rigorous formal definition using a two-level grammar

While the language never became as popular as C or Pascal, its influence on programming language design is undeniable. Steve Bourne, creator of the Bourne shell, and language designers working on C and C++ all drew inspiration from ALGOL 68.

The Hello World Program

Let’s start with the classic “Hello, World!” program in ALGOL 68. Create a file named hello.a68:

print(("Hello, World!", newline))

That’s it! This simple one-liner demonstrates several ALGOL 68 features:

  • print: The standard output procedure
  • Double parentheses (( )): The outer parentheses are for the print procedure call, the inner ones create a structure (like a tuple)
  • "Hello, World!": A string literal
  • newline: A built-in constant that represents a line break
  • Comma ,: Separates the string from the newline in the structure

Understanding ALGOL 68 Syntax

The double parentheses might look unusual if you’re coming from C or Python. In ALGOL 68:

  • print(x) prints a single value x
  • To print multiple values, you pass them as a structure: print((a, b, c))
  • The inner parentheses create what ALGOL 68 calls a “row” or structure of values

Running with Docker

We’ll use Docker to run ALGOL 68 programs using Algol 68 Genie (a68g), a modern implementation that faithfully implements the ALGOL 68 standard.

Pull the Docker Image

1
docker pull codearchaeology/algol68:latest

This image is based on Debian Bookworm and includes Algol 68 Genie version 3.1.2.

Run Your Program

1
docker run --rm -v $(pwd):/app -w /app codearchaeology/algol68:latest hello.a68

Let’s break down this command:

  • docker run: Runs a container from an image
  • --rm: Automatically removes the container after it exits
  • -v $(pwd):/app: Mounts your current directory to /app in the container
  • -w /app: Sets the working directory to /app
  • codearchaeology/algol68:latest: The image to use
  • hello.a68: The file to execute

Expected Output

Hello, World!

Building Your Own Docker Image

If you’d like to build the Docker image yourself, create a Dockerfile:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
FROM debian:bookworm-slim

RUN apt-get update && \
    apt-get install -y --no-install-recommends algol68g && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app

ENTRYPOINT ["a68g"]

Build it with:

1
2
docker build -t my-algol68 .
docker run --rm -v $(pwd):/app -w /app my-algol68 hello.a68

Alternative Hello World Forms

ALGOL 68’s flexibility allows for several ways to write Hello World:

Using printf

printf(($"Hello, World!"l$))

The $...$ syntax defines a format pattern. The l stands for “newline”.

Using Explicit Output

put(stand out, ("Hello, World!", newline))

Here, stand out is ALGOL 68’s name for standard output.

Multiple Lines

BEGIN
  print("Hello, World!");
  print(newline)
END

ALGOL 68 uses BEGIN and END to delimit blocks (similar to { and } in C).

Understanding ALGOL 68 Modes

In ALGOL 68, types are called “modes”. Our program uses:

  • STRING: Text mode for string literals
  • Built-in procedures: print and printf are standard procedures

ALGOL 68’s mode system was remarkably sophisticated for its time, featuring:

  • Automatic dereferencing
  • Coercion (automatic type conversion)
  • User-defined modes (custom types)
  • Mode unions (early version of union types)

Next Steps

Now that you’ve successfully run your first ALGOL 68 program, you can explore more features:

  1. Variables and Constants: Learn about ALGOL 68’s mode system
  2. Operators: Create custom operators with your own precedence
  3. Procedures: Define functions and procedures
  4. Arrays: Work with flexible arrays
  5. Structures: Create complex data types

Historical Context

Running ALGOL 68 today connects you to a pivotal moment in programming language history. When you write print(("Hello, World!", newline)), you’re using syntax and concepts that influenced:

  • C’s printf: ALGOL 68’s formatted I/O inspired C’s printf
  • Shell scripting: The Bourne shell’s syntax borrowed from ALGOL 68
  • Modern type systems: Many languages adopted ALGOL 68’s approach to types
  • Operator overloading: ALGOL 68 was one of the first languages to allow it

Troubleshooting

Docker Not Found

Ensure Docker is installed and running:

1
docker --version

Permission Denied

On Linux, you may need to add your user to the docker group:

1
sudo usermod -aG docker $USER

Then log out and back in.

File Not Found

Make sure you’re running the Docker command from the directory containing hello.a68:

1
ls -la hello.a68

Resources

Conclusion

Congratulations! You’ve written and executed your first ALGOL 68 program. While ALGOL 68 may not be used in modern production systems, understanding it provides valuable insights into programming language design and the evolution of the languages we use today.

The journey from ALGOL 68’s print(("Hello, World!", newline)) to modern languages shows how computer science builds on the innovations of the past. Every time you use operator overloading in C++, format strings in C, or shell scripts in Unix, you’re benefiting from ideas pioneered in ALGOL 68.

Happy coding, and enjoy your exploration of this fascinating historical language!

Running Today

All examples can be run using Docker:

docker pull codearchaeology/algol68:latest
Last updated: