Pangram verdict · v3.3
We believe that this document is a mix of AI-generated, and human-written content
AI likelihood · overall
MixedArticle text · 1,836 words · 8 segments analyzed
The MUMPS Primer: An Introduction and Tutorial for the 1976 Standard Table of Contents 1. Introduction 1.1. What is MUMPS? 1.2. The 1976 Standard 1.3. Who This Book Is For 1.4. Getting Started 2. The Language at a Glance 2.1. Everything Is a String 2.2. No Operator Precedence 2.3. Line-Oriented Structure 2.4. Commands Are Terse 2.5. The Persistent Database Is Built In 3. Variables and Data Types 3.1. Local Variables 3.2. Subscripted Variables 3.3. Strings, Numbers, and Automatic Conversion 3.4. Truth Values 4. Expressions and Operators 4.1. Strict Left-to-Right Evaluation 4.2. Arithmetic Operators 4.3. Unary Operators 4.4. Relational Operators 4.5. Logical Operators 4.6. The Concatenation Operator 4.7. Pattern Match 5. Commands 5.1. SET — Assign a Value 5.2. WRITE — Output Data 5.3. READ — Input Data 5.4. IF and ELSE — Conditional Execution 5.5. Post-Conditionals 5.6. FOR — Repetition 5.7.
DO — Call a Subroutine 5.8. GOTO — Transfer Control 5.9. QUIT — Return from Subroutine or Exit FOR 5.10. HALT and HANG 5.11. XECUTE — Execute a String as Code 5.12. KILL — Delete Variables 5.13. BREAK 6. String Functions 6.1. $LENGTH — String Length 6.2. $EXTRACT — Substring by Position 6.3. $PIECE — Substring by Delimiter 6.4. $FIND — Search for Substring 6.5. $JUSTIFY — Right-Justify and Format Numbers 6.6. $ASCII and $CHAR — Character Code Conversion 6.7. $RANDOM — Random Number 6.8. $SELECT — Conditional Expression 6.9. $TEXT — Retrieve Source Line 7. The Global Database 7.1. Global Variables 7.2. Building a Data Model 7.3. $DATA — Testing Whether a Node Exists 7.4. $NEXT — Walking the Tree 7.5. The Naked Reference 7.6. KILL on Globals 8. Input/Output 8.1. Formatting Output 8.2. The Special Variables $X and $Y 8.3. Device I/O (Overview) 9. Indirection 9.1. Name Indirection 9.2. Subscript Indirection 9.3. Argument Indirection 9.4. Pattern Indirection 10. Special Variables 10.1. $HOROLOG — Date and Time 10.2. $IO — Current Device 10.3. $JOB — Process Identifier 10.4. $STORAGE — Available Space 10.5. $TEST — Last Test Result 10.6. $X and $Y — Cursor Position 11. Routines and Program Structure 11.1. Routine Structure 11.2. Lines and Labels 11.3. Entry References 11.4. Command Abbreviations 12. Putting It All Together 13.
Command Reference 13.1. BREAK 13.2. CLOSE 13.3. DO 13.4. ELSE 13.5. FOR 13.6. GOTO 13.7. HALT 13.8. HANG 13.9. IF 13.10. KILL 13.11. LOCK 13.12. OPEN 13.13. QUIT 13.14. READ 13.15. SET 13.16. USE 13.17. VIEW 13.18. WRITE 13.19. XECUTE 14. Function Reference 14.1. $ASCII 14.2. $CHAR 14.3. $DATA 14.4. $EXTRACT 14.5. $FIND 14.6. $JUSTIFY 14.7. $LENGTH 14.8. $NEXT 14.9. $PIECE 14.10. $RANDOM 14.11. $SELECT 14.12. $TEXT 15. Special Variables Reference 15.1. $HOROLOG 15.2. $IO 15.3. $JOB 15.4. $STORAGE 15.5. $TEST 15.6. $X 15.7. $Y 16. Operators Reference 16.1. Unary Operators 16.2. Binary Operators 17. Syntax Summary 17.1. Line Structure 17.2. Routine Structure 17.3. Name Syntax 17.4. Variable Syntax 17.5. Numeric Literal Syntax 17.6. String Literal Syntax 17.7. Entry Reference Syntax Appendix A: ASCII Code Table Appendix B: Glossary 18. What We Have Not Covered References 1. Introduction 1.1. What is MUMPS?
In 1966, at the Laboratory of Computer Science at Massachusetts General Hospital in Boston, Octo Barnett, Neil Pappalardo, and Curtis Marble created a programming language called MUMPS — the Massachusetts General Hospital Utility Multi-Programming System. MUMPS was born from a practical need: hospitals required a system where doctors and nurses could simultaneously access and update patient data from multiple terminals, in real time, on affordable hardware. In 1966, "affordable hardware" meant a DEC PDP-7 with 8K words of memory and a small disk. There was no room for separate layers — no separate operating system, file system, database server, and application language stacked on top of each other.
Everything had to be one integrated system. What emerged was something remarkable: a programming language with a built-in hierarchical database — what the database world would not have a name for until four decades later: a NoSQL database with an integrated programming language. The core data abstraction in MUMPS is the global variable: a hierarchical, sparse array that is stored persistently on disk and shared among all concurrent users. In today’s terms, globals are a schema-free, ordered key-value store with composite keys, created on first assignment and deleted on demand. SET ^PATIENT(12345,"NAME")="Smith, John" SET ^PATIENT(12345,"DOB")="1945-03-15" SET ^PATIENT(12345,"LAB","2024-01-15","GLUCOSE")=95 There is no CREATE TABLE, no schema definition, no INSERT statement. You simply SET a value at a hierarchical path, and the system creates whatever intermediate nodes are necessary. KILL a node, and the entire subtree beneath it disappears. Consider what MUMPS had in 1966 that the rest of the computing world would spend decades reinventing: Schema-free storage: No declarations required. Nodes are created on first assignment. This is what MongoDB would call "schemaless documents" in 2009. Hierarchical data model: Patient records naturally form trees. MUMPS globals mirror this structure directly. This is what Firebase would call "real-time hierarchical data" in 2012. Ordered key traversal: The $NEXT function walks through sibling nodes in sorted order without an explicit index — what Redis would call "sorted sets" in 2009, or LevelDB "ordered iteration" in 2011. Integrated language and database: There is no impedance mismatch. Variables and database nodes use the same syntax, the same data types, the same operations. All of this ran on a machine with 8 kilobytes of memory, serving multiple simultaneous users. 1.2. The 1976 Standard By the early 1970s, multiple vendors had created their own incompatible MUMPS dialects. The MUMPS Development Committee (MDC), formed in 1972, set out to create a common standard.
The result was published in January 1976 by the U.S. National Bureau of Standards as NBS Handbook 118: "MUMPS Language Standard". A companion document, the Programmers' Reference Manual (MDC/42), was written by Melvin Conway (of "Conway’s Law" fame) later that year. Together they form the first complete, formal specification of MUMPS. The 1976 standard is astonishingly minimal: 19 commands: BREAK, CLOSE, DO, ELSE, FOR, GOTO, HALT, HANG, IF, KILL, LOCK, OPEN, QUIT, READ, SET, USE, VIEW, WRITE, XECUTE 12 functions: $ASCII, $CHAR, $DATA, $EXTRACT, $FIND, $JUSTIFY, $LENGTH, $NEXT, $PIECE, $RANDOM, $SELECT, $TEXT 7 special variables: $HOROLOG, $IO, $JOB, $STORAGE, $TEST, $X, $Y That is the entire language. No JOB command (no programmatic multi-tasking). No NEW command (no local variable scoping — that came in 1984). Subscripts restricted to nonnegative integers for portability. Maximum string length of 255 characters. Yet this was sufficient to build hospital information systems serving millions of patients. This primer covers exactly this 1976 standard — the essential, crystallized MUMPS, before decades of extensions. 1.3. Who This Book Is For This book is for programmers who are fluent in at least one other language and want to understand what MUMPS was, how it worked, and what made it historically significant. You do not need any prior MUMPS experience. The book serves three purposes: Introduction: What MUMPS is and why it matters. Tutorial: A progressive, example-driven walkthrough of the language that you can follow along interactively. Quick reference: A summary of all commands, functions, and special variables for the 1976 standard. We focus on single-user operation. Multi-user features like LOCK and device sharing are mentioned where relevant, but their full treatment is deferred.
1.4. Getting Started To follow along with the examples, start the MUMPS interpreter in interactive mode. You will see a prompt: > At this prompt you can type any MUMPS command and it will be executed immediately. Try: >WRITE "Hello, World!",! Hello, World! The ! after the comma is a format code that produces a new line. We will explain the syntax in detail shortly. To exit the interpreter, type: >HALT You can also run MUMPS programs in batch mode by loading routine files. But for learning, interactive mode is ideal — it gives you immediate feedback on every command. 2. The Language at a Glance Before diving into the details, here is a bird’s-eye view of MUMPS for the programmer coming from another language. MUMPS has several features that will feel unfamiliar — deliberately so, because they reflect a different set of design trade-offs. 2.1. Everything Is a String MUMPS has exactly one data type: the character string. Numbers are simply strings that happen to look numeric. The string "42" and the number 42 are the same value. When you perform arithmetic, MUMPS automatically interprets strings as numbers; when you concatenate, it treats values as strings. There are no type declarations, no type errors, and no conversions to worry about. 2.2. No Operator Precedence All binary operators are evaluated strictly left to right. There is no multiplication-before-addition rule. The expression 2+3*4 evaluates to 20, not 14, because 2+3 is computed first (giving 5), then 5*4 gives 20. Use parentheses to override this: 2+(3*4) gives 14. This is unfamiliar, but it eliminates an entire class of bugs related to precedence misunderstandings. 2.3. Line-Oriented Structure A MUMPS program is a sequence of lines. Each line has an optional label (for reference by DO, GOTO, or $TEXT), followed by a mandatory space separator, followed by zero or more commands separated by single spaces: LABEL command1 argument command2 argument ;comment Spaces are syntactically significant. A single space separates the command word from its argument. Two spaces (or end of line) separate an argumentless command from the next command or comment.
A semicolon begins a comment that extends to end of line. 2.4. Commands Are Terse Every command has a full name and a one-letter abbreviation. Both are always valid. SET X=1 and S X=1 are identical. WRITE and W, IF and I, FOR and F, and so on. Experienced MUMPS programmers universally use the abbreviations, making MUMPS code extremely dense. In this tutorial we generally use the full command names for clarity, with the abbreviation noted. 2.5. The Persistent Database Is Built In Any variable whose name starts with a caret (^) is a global variable: it is stored persistently on disk, survives process termination, and is shared among all users. Variables without a caret are local variables: they exist only in the current process’s memory and vanish when the process ends. Global and local variables use exactly the same syntax for subscripts, assignment, and deletion. 3. Variables and Data Types 3.1. Local Variables A local variable name starts with a letter or %, followed by letters and digits: >SET NAME="Alice" >SET AGE=30 >SET %TEMP=98.6 >WRITE NAME," is ",AGE," years old.",! Alice is 30 years old. Variable names are case-sensitive: Name, NAME, and name are three different variables. Note In the 1976 standard, portable routine names and labels are limited to 8 significant characters (uppercase only for routine names), but local variable names follow the same name syntax: a letter or % followed by alphanumerics. 3.2. Subscripted Variables Any variable can have subscripts, forming a hierarchical tree: >SET PATIENT("NAME")="Smith, John" >SET PATIENT("AGE")=45 >SET PATIENT("LAB",1)="Glucose: 95" >SET PATIENT("LAB",2)="Cholesterol: 210" An unsubscripted variable and its subscripted forms coexist independently. PATIENT can hold a value while PATIENT("NAME") holds a different one — they are separate nodes in the same tree. 3.3. Strings, Numbers, and Automatic Conversion Every value in MUMPS is a string.