Beginner

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:

1
2
	OUTPUT = "Hello, World" CHAR(33)
END

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:

1
2
3
4
5
# Pull the Docker image
docker pull esolang/snobol:latest

# Run the program
docker run --rm -v $(pwd):/app -w /app esolang/snobol:latest snobol hello.sno

What These Commands Do

  1. docker pull esolang/snobol:latest - Downloads the SNOBOL interpreter image
  2. docker run --rm -v $(pwd):/app -w /app - Runs a container with your current directory mounted
  3. snobol hello.sno - The SNOBOL interpreter runs your program

Running Locally

If you want to install SNOBOL4 on your system:

Debian/Ubuntu

1
2
3
4
5
# Install CSNOBOL4
apt install snobol4

# Run the program
snobol4 hello.sno

From Source (CSNOBOL4)

Download from https://www.regressive.org/snobol4/csnobol4/ and build:

1
2
3
./configure
make
make install

Expected Output

Hello, World!

Alternative Approaches

Using PUNCH for Output

SNOBOL has multiple output mechanisms. PUNCH was originally for punch card output:

1
2
        PUNCH = "Hello, World!"
END

Using Multiple Outputs

You can output multiple lines:

1
2
3
        OUTPUT = "Hello,"
        OUTPUT = "World!"
END

This outputs:

Hello,
World!

Using String Concatenation

SNOBOL uses simple juxtaposition (placing things next to each other) for concatenation:

1
2
3
4
        GREETING = "Hello"
        TARGET = "World"
        OUTPUT = GREETING ", " TARGET "!"
END

A Glimpse of Pattern Matching

Even in a simple program, we can show SNOBOL’s unique feature - pattern matching:

1
2
3
4
        MESSAGE = "Hello, World!"
        MESSAGE "World" = "SNOBOL"
        OUTPUT = MESSAGE
END

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

  1. Whitespace Matters - Statements must not start in column 1
  2. OUTPUT Variable - Special variable for printing
  3. String Literals - Enclosed in double quotes
  4. END Statement - Required at the end of every program
  5. No Semicolons - Each line is a complete statement

The INPUT and OUTPUT Variables

SNOBOL uses special variables for I/O:

VariablePurpose
INPUTRead a line from standard input
OUTPUTWrite a line to standard output
PUNCHWrite to “punch” output (originally punch cards)
TERMINALDirect 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
Last updated: