Beginner

Hello World in ALGOL 60

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

Introduction

Welcome to ALGOL 60! This tutorial will guide you through writing and running your first ALGOL 60 program. ALGOL 60, designed in 1960, is one of the most influential programming languages in history. While you may never use it in production, understanding ALGOL 60 provides invaluable insight into where modern programming languages came from.

What is ALGOL 60?

ALGOL 60 (Algorithmic Language 1960) was designed by an international committee of computer scientists to create a universal language for expressing algorithms. The language introduced many concepts we now take for granted:

  • Block structure with begin and end
  • Lexical scoping of variables
  • Recursive procedures
  • Formal syntax definition using Backus-Naur Form (BNF)

Nearly every programming language you use today—C, Java, Python, JavaScript—owes something to ALGOL 60.

The Hello World Program

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

begin
  outstring(1, "Hello, World!");
  outstring(1, "\n")
end

This simple program demonstrates several ALGOL 60 features:

  • begin and end: Block delimiters (ancestors of { and } in C)
  • outstring: Output procedure from the Modified Report
  • 1: The channel number for standard output
  • String literals: Enclosed in double quotes
  • \n: Newline character

Understanding the I/O

ALGOL 60’s original specification famously did not include input/output operations—the designers wanted to focus purely on algorithmic expression. Different implementations added their own I/O procedures.

GNU MARST uses the procedures defined in the Modified Report on ALGOL 60:

  • outstring(channel, string) - Output a string
  • outinteger(channel, number) - Output an integer
  • outreal(channel, number) - Output a real number

Channel 1 represents standard output.

Running with Docker

We’ll use Docker to run ALGOL 60 programs using GNU MARST, which translates ALGOL 60 to C and then compiles the result.

Pull the Docker Image

1
docker pull codearchaeology/algol60:latest

This image includes GNU MARST 2.8 and the necessary C compiler for the final compilation step.

Run Your Program

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

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/algol60:latest: The image to use
  • algol60-run hello.alg: Compiles and runs the ALGOL 60 source file

Expected Output

Hello, World!

How MARST Works

GNU MARST compiles ALGOL 60 programs through a two-stage process:

  1. Translation: The marst tool translates ALGOL 60 source code to C
  2. Compilation: GCC compiles the C code and links it with the ALGOL library

This approach allows ALGOL 60 programs to benefit from modern C compiler optimizations while maintaining compatibility with the 1960 language specification.

Alternative Syntax Forms

ALGOL 60 supports several ways to delimit programs and blocks. Here are some variations:

Using Quote Stropping

Traditional ALGOL 60 used quote stropping for keywords:

'begin'
  outstring(1, "Hello, World!");
  outstring(1, "\n")
'end'

GNU MARST accepts both reserved word style (without quotes) and quote stropping.

Longer Example with Comments

begin
  comment This is our first ALGOL 60 program;
  comment ALGOL 60 uses semicolons to terminate comments;

  outstring(1, "Hello, World!");
  outstring(1, "\n")
end

Note that ALGOL 60 comments start with comment and end with a semicolon.

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
11
12
FROM debian:bookworm-slim

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential wget ca-certificates && \
    wget -q https://ftp.gnu.org/gnu/marst/marst-2.8.tar.gz && \
    tar -xzf marst-2.8.tar.gz && \
    cd marst-2.8 && ./configure && make && make install && \
    cd .. && rm -rf marst-2.8 marst-2.8.tar.gz && \
    apt-get clean

WORKDIR /app

Build and run it with:

1
2
3
docker build -t my-algol60 .
docker run --rm -v $(pwd):/app -w /app my-algol60 sh -c \
  'marst hello.alg -o hello.c && gcc hello.c -lalgol -lm -o hello && ./hello'

Historical Context

When you run this Hello World program, you’re connecting with computing history. The same basic program structure—a block containing statements—appears in languages from Pascal (1970) through C (1972) to JavaScript (1995) and beyond.

ALGOL 60’s influence is visible in:

  • Block structure: begin/end became {/} in C
  • Semicolons: Statement terminators remain ubiquitous
  • Comments: The concept of inline documentation
  • Lexical scope: How modern languages resolve variable names

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.alg:

1
ls -la hello.alg

Compilation Errors

ALGOL 60 is case-insensitive for keywords but case-sensitive for identifiers. Make sure:

  • Keywords like begin, end, comment are lowercase
  • String literals are properly quoted with double quotes
  • Each statement (except the last in a block) ends with a semicolon

Next Steps

Now that you’ve run your first ALGOL 60 program, you can explore:

  1. Variables: Learn about ALGOL 60’s type system with integer, real, and Boolean
  2. Procedures: Define and call procedures with parameters
  3. Control Structures: Use if, for, and goto statements
  4. Arrays: Work with static and dynamic arrays

Resources

  • GNU MARST Documentation: https://www.gnu.org/software/marst/
  • ALGOL 60 Wikipedia: Historical overview and language features
  • Revised Report on ALGOL 60: The official language specification
  • ACM Digital Library: Classic algorithms published in ALGOL 60 notation

Conclusion

Congratulations! You’ve written and executed your first ALGOL 60 program. While ALGOL 60 is not used in modern production systems, understanding it provides a window into how programming languages evolved.

The concepts you’ve seen—blocks, statements, procedures, and structured programming—form the foundation of almost every language you’ll encounter. When you write a function in Python or a method in Java, you’re using ideas that were first formalized in ALGOL 60 over six decades ago.

Happy coding, and enjoy exploring this foundational language!

Running Today

All examples can be run using Docker:

docker pull codearchaeology/algol60:latest
Last updated: