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 theprintprocedure call, the inner ones create a structure (like a tuple) "Hello, World!": A string literalnewline: 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 valuex- 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
| |
This image is based on Debian Bookworm and includes Algol 68 Genie version 3.1.2.
Run Your Program
| |
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/appin the container-w /app: Sets the working directory to/appcodearchaeology/algol68:latest: The image to usehello.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:
| |
Build it with:
| |
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:
printandprintfare 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:
- Variables and Constants: Learn about ALGOL 68’s mode system
- Operators: Create custom operators with your own precedence
- Procedures: Define functions and procedures
- Arrays: Work with flexible arrays
- 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:
| |
Permission Denied
On Linux, you may need to add your user to the docker group:
| |
Then log out and back in.
File Not Found
Make sure you’re running the Docker command from the directory containing hello.a68:
| |
Resources
- Algol 68 Genie Documentation: https://jmvdveer.home.xs4all.nl/en.algol-68-genie.html
- ALGOL 68 Wikipedia: Historical overview and language features
- Revised Report on ALGOL 68: The official language specification (for the truly dedicated!)
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