Hello World in SNOBOL
Your first SNOBOL program - the classic Hello World example with Docker setup
Every programming journey starts with Hello World. Let’s write our first SNOBOL program and get a glimpse of this pioneering pattern-matching language from Bell Labs.
The Code
Create a file named hello.sno:
| |
Understanding the Code
This simple program demonstrates SNOBOL’s basic structure:
- Leading whitespace - SNOBOL statements must start with whitespace (space or tab). Column 1 is reserved for labels.
OUTPUT- A special variable that sends text to standard output when assigned"Hello, World" CHAR(33)- String concatenation: the literal string followed by the exclamation mark (ASCII 33)END- Marks the end of the program (required)
Note: We use CHAR(33) for the exclamation mark because some SNOBOL interpreters treat ! specially in string literals. The CHAR() function returns the character for a given ASCII code.
Why the Indentation?
SNOBOL’s syntax comes from its assembly language heritage. In early SNOBOL:
- Column 1 was for labels (used as goto targets)
- Statements had to start in column 2 or later
Modern SNOBOL interpreters are more flexible, but the convention remains.
Running with Docker
The easiest way to run SNOBOL without installing it locally:
| |
What These Commands Do
docker pull esolang/snobol:latest- Downloads the SNOBOL interpreter imagedocker run --rm -v $(pwd):/app -w /app- Runs a container with your current directory mountedsnobol hello.sno- The SNOBOL interpreter runs your program
Running Locally
If you want to install SNOBOL4 on your system:
Debian/Ubuntu
| |
From Source (CSNOBOL4)
Download from https://www.regressive.org/snobol4/csnobol4/ and build:
| |
Expected Output
Hello, World!
Alternative Approaches
Using PUNCH for Output
SNOBOL has multiple output mechanisms. PUNCH was originally for punch card output:
| |
Using Multiple Outputs
You can output multiple lines:
| |
This outputs:
Hello,
World!
Using String Concatenation
SNOBOL uses simple juxtaposition (placing things next to each other) for concatenation:
| |
A Glimpse of Pattern Matching
Even in a simple program, we can show SNOBOL’s unique feature - pattern matching:
| |
This outputs:
Hello, SNOBOL!
The statement MESSAGE "World" = "SNOBOL" finds “World” in MESSAGE and replaces it with “SNOBOL”.
SNOBOL Statement Structure
A SNOBOL statement has this general form:
label subject pattern = replacement :goto
For our Hello World:
- label: None (would be in column 1)
- subject:
OUTPUT - pattern: None
- replacement:
"Hello, World!" - goto: None
The simplest form is just assignment: VARIABLE = value
Key Concepts
- Whitespace Matters - Statements must not start in column 1
- OUTPUT Variable - Special variable for printing
- String Literals - Enclosed in double quotes
- END Statement - Required at the end of every program
- No Semicolons - Each line is a complete statement
The INPUT and OUTPUT Variables
SNOBOL uses special variables for I/O:
| Variable | Purpose |
|---|---|
INPUT | Read a line from standard input |
OUTPUT | Write a line to standard output |
PUNCH | Write to “punch” output (originally punch cards) |
TERMINAL | Direct terminal I/O (implementation dependent) |
Historical Note
SNOBOL was created at Bell Labs starting in 1962 by David Farber, Ralph Griswold, and Ivan Polonsky. The version you’re using (SNOBOL4, released in 1967) introduced patterns as first-class data types - a revolutionary concept that influenced Perl, AWK, and many other languages.
The name stands for StriNg Oriented and symBOlic Language, emphasizing its focus on string manipulation rather than numerical computation.
Next Steps
Continue exploring SNOBOL’s unique features:
- Variables and data types
- Pattern matching basics
- Success and failure - SNOBOL’s control flow mechanism
- Built-in patterns (ARB, SPAN, BREAK, ANY)
- User-defined patterns
- Tables (SNOBOL’s associative arrays)
SNOBOL will introduce you to pattern-directed programming - a paradigm where pattern matching drives your program’s behavior. It’s the ancestor of the regex and pattern matching features you use in modern languages.
Welcome to SNOBOL - where patterns are first-class citizens!
Running Today
All examples can be run using Docker:
docker pull esolang/snobol:latest