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
beginandend - 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:
beginandend: Block delimiters (ancestors of{and}in C)outstring: Output procedure from the Modified Report1: 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 stringoutinteger(channel, number)- Output an integeroutreal(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
| |
This image includes GNU MARST 2.8 and the necessary C compiler for the final compilation step.
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/algol60:latest: The image to usealgol60-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:
- Translation: The
marsttool translates ALGOL 60 source code to C - 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:
| |
Build and run it with:
| |
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/endbecame{/}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:
| |
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.alg:
| |
Compilation Errors
ALGOL 60 is case-insensitive for keywords but case-sensitive for identifiers. Make sure:
- Keywords like
begin,end,commentare 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:
- Variables: Learn about ALGOL 60’s type system with
integer,real, andBoolean - Procedures: Define and call procedures with parameters
- Control Structures: Use
if,for, andgotostatements - 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