Beginner

Hello World in MUMPS

Your first MUMPS program - the classic Hello World example with Docker setup

Every programming journey starts with Hello World. Let’s write our first MUMPS program using YottaDB, an open-source MUMPS implementation.

The Code

Create a file named hello.m:

hello ; Hello World in MUMPS
 write "Hello, World!",!
 quit

Understanding the Code

  • hello - A label starting in column 1. This is the routine name and must match the filename (without the .m extension).
  • ; Hello World in MUMPS - A comment. Everything after ; on a line is a comment.
  • write "Hello, World!",! - Note the leading space! Executable code must be indented. The write command outputs text. The ,! after the string outputs a newline.
  • quit - Ends execution of the routine. Also indented with a leading space.

Why the Leading Space Matters

In MUMPS, the first character of each line has special meaning:

  • Column 1 starts with a letter = This is a label (routine name, subroutine name)
  • Column 1 starts with a space or tab = This is executable code
  • Column 1 starts with ; = This is a comment line

Forgetting the leading space on executable lines is the most common beginner mistake.

Running with Docker

The easiest way to run MUMPS without installing YottaDB locally:

1
2
3
4
5
# Pull the YottaDB image
docker pull yottadb/yottadb-base:latest-master

# Run the program
docker run --rm -v $(pwd):/app -e ydb_routines=/app yottadb/yottadb-base:latest-master yottadb -run hello

How the Docker Command Works

  • -v $(pwd):/app - Mounts your current directory into the container at /app
  • -e ydb_routines=/app - Tells YottaDB where to find your .m routine files
  • yottadb -run hello - Runs the routine named hello (from hello.m)

Running Locally

If you have YottaDB installed on Linux:

1
2
3
4
5
# Set the routine search path
export ydb_routines=/path/to/your/routines

# Run the routine
yottadb -run hello

Installing YottaDB

YottaDB runs natively on Linux. For macOS and Windows, use Docker or WSL.

Ubuntu/Debian:

1
2
3
4
5
6
# Download and install YottaDB
mkdir /tmp/tmp
cd /tmp/tmp
wget https://download.yottadb.com/ydbinstall.sh
chmod +x ydbinstall.sh
sudo ./ydbinstall.sh --utf8 default --verbose

Expected Output

Hello, World!

MUMPS Interactive Mode

YottaDB also provides an interactive prompt (called “Direct Mode”) where you can type MUMPS commands directly:

1
2
# Start interactive mode
docker run --rm -it yottadb/yottadb-base:latest-master yottadb -direct

At the YDB> prompt, you can type:

YDB>write "Hello, World!",!
Hello, World!
YDB>halt

Command Abbreviations

One of MUMPS’s distinctive features is that every command can be abbreviated to its first letter. Our Hello World could also be written as:

hello ; Hello World abbreviated
 w "Hello, World!",!
 q

Here w is short for write and q is short for quit. In production MUMPS code, abbreviations are extremely common.

Key Concepts

  1. MUMPS has an integrated database - The language includes a built-in hierarchical database, making it unique among programming languages
  2. Indentation is significant - Code lines must start with a space; labels start in column 1
  3. Routines = files - A routine named hello must be in a file named hello.m
  4. Commands are abbreviated - write can be w, set can be s, quit can be q
  5. Typeless - Variables have no declared type; values are coerced as needed between strings and numbers
  6. Case insensitive - WRITE, Write, and write are all the same command

A Bit of History

When MUMPS was created in 1967 at Massachusetts General Hospital, it ran on a DEC PDP-7 with limited memory. The language’s terse syntax and command abbreviations were not just stylistic choices - they were practical necessities to fit programs into the small memory available. Today, those same abbreviations remain a hallmark of the language, and MUMPS continues to power healthcare information systems that serve millions of patients.

Running Today

All examples can be run using Docker:

docker pull yottadb/yottadb-base:latest-master
Last updated: