Shakespeare
An esoteric programming language where programs are written as Shakespearean plays, with characters as variables and dialogue as operations.
Created by Karl Hasselström and Jon Åslund
The Shakespeare Programming Language (SPL) transforms code into drama. Every program reads like a play by William Shakespeare, complete with character declarations, acts, scenes, and dramatic dialogue. Behind the poetic facade lies a Turing-complete programming language capable of any computation.
History & Origins
Karl Hasselström and Jon Åslund created SPL in February 2001 while students at the Royal Institute of Technology (KTH) in Stockholm, Sweden. The language emerged from a syntax analysis course where the final project allowed students to demonstrate what they had learned in any way they chose.
The story goes that while pulling an all-nighter to finish a previous assignment, Hasselström and Åslund spent more time inventing the Shakespeare Programming Language than meeting their deadline. Most of the language design was done that first night, with details and implementation refined over the following weeks.
Design Philosophy
The design goal was simple but ambitious: create a programming language with source code that resembles Shakespeare plays. Like the Chef programming language (which makes programs look like recipes), SPL belongs to a category of esoteric languages where the code is designed to appear as something other than code.
The result is wonderfully absurd - a programming language where insults decrease variable values and compliments increase them, where characters enter and exit stages to control scope, and where “Speak your mind!” is a perfectly valid output statement.
How SPL Works
Understanding SPL requires thinking about programming in a completely different way:
Characters as Variables
Every SPL program begins with a Dramatis Personae - the list of characters who will appear in the play. Each character is a variable that can store a signed integer value:
Romeo, a young man with a remarkable patience.
Juliet, a likewise young woman of remarkable grace.
The descriptions after the names are ignored by the compiler but required for the play format. Character names must be from Shakespeare’s works (Romeo, Juliet, Hamlet, Ophelia, etc.).
Acts and Scenes as Labels
The program is divided into Acts and Scenes, numbered with Roman numerals:
Act I: Hamlet's insults and flattery.
Scene I: The insulting of Romeo.
Acts and scenes serve as GOTO labels - you can jump to any act or scene during execution.
Stage Directions as Control Flow
Characters must be “on stage” to interact:
[Enter Hamlet and Romeo]
[Exit Romeo]
[Exeunt] (everyone leaves)
Only two characters can be on stage at once for dialogue. Stage directions control which variables are in scope.
Dialogue as Operations
The actual computation happens in dialogue. When a character speaks, they typically address another character on stage:
Setting Values: Values are constructed from nouns and adjectives:
- Positive nouns (hero, angel, flower) = 1
- Negative nouns (coward, devil, pig) = -1
- Each adjective multiplies by 2
So “a beautiful wonderful amazing flower” = 2 × 2 × 2 × 1 = 8
Arithmetic: Mathematical operations are embedded in prose:
- “the sum of X and Y”
- “the difference between X and Y”
- “the product of X and Y”
- “the quotient between X and Y”
Output:
- “Speak your mind!” - output the value as an ASCII character
- “Open your heart!” - output the value as a number
Input:
- “Listen to your heart!” - read a number
- “Open your mind!” - read a character
Comparisons and Conditionals:
- “Am I better than you?” - compare values
- “If so, let us proceed to scene III” - conditional jump
The Stack
Each character also maintains a stack, enabling more complex operations:
- “Remember X” - push to stack
- “Recall” - pop from stack
Example: How Hello World Works
The classic Hello World in SPL works by:
- Constructing the ASCII value for each character (H=72, e=101, l=108, etc.)
- Outputting each value with “Speak your mind!”
- Using arithmetic to efficiently build larger numbers
For example, to output ‘H’ (ASCII 72):
- Instead of saying 72 positive words, use multiplication
- “the product of the product of the product of a hero and a hero and a hero and the sum of a hero and a hero and a hero”
- This computes 2³ × (1 + 1 + 1) × 3 = 8 × 9 = 72
Implementations
Original C Compiler
The original implementation by Hasselström and Åslund compiles SPL to C code, which is then compiled with a standard C compiler. This remains one of the most complete implementations.
shakespearelang (Python)
A modern Python-based interpreter available via pip:
| |
Features include:
- Direct execution of SPL programs
- Debugging capabilities
- Better error messages than the original compiler
Docker Image (esolang/spl)
The easiest way to run SPL programs without installation:
| |
Turing Completeness
Despite its unusual syntax, SPL is Turing complete. This can be proven by demonstrating that any Brainfuck program can be converted to SPL, which has been done. SPL has:
- Variables (characters)
- Arithmetic operations
- Conditional branching
- Loops (via scene/act jumps)
- Memory (character stacks)
These primitives are sufficient for universal computation.
Writing SPL Programs
Tips for Beginners
- Start with the structure: Plan your acts, scenes, and characters before writing dialogue
- Use small numbers: Build large values with multiplication
- Track who’s on stage: Only two characters at a time for dialogue
- Mind your adjectives: Each adjective doubles the value
- Test frequently: SPL errors can be cryptic
Common Patterns
Outputting a string: Set a value, speak it, modify it, repeat
Juliet: You are as lovely as a rose. Speak your mind!
Looping: Jump back to an earlier scene
Let us return to scene I.
Conditional execution:
Am I better than you? If so, let us proceed to scene V.
The SPL Community
SPL has inspired programmers and artists to create programs that are genuinely entertaining to read. The language demonstrates that code can have aesthetic value - that programs need not be purely functional documents but can be creative expressions.
Some have written programs that work both as valid Shakespeare (or Shakespearean parody) and as functional programs. Others have used SPL to explore questions about the nature of programming languages and human communication.
File Format
SPL programs use the .spl file extension. The file should:
- Start with a title (the play’s name)
- Include a Dramatis Personae section
- Be divided into Acts and Scenes
- Use proper stage directions and dialogue format
Continue to the Hello World tutorial to write your first dramatic program.
Timeline
Notable Uses & Legacy
Educational Programming
Teaching unconventional approaches to computation and creative coding.
Code Artistry
Creating programs that double as dramatic literature.
Esoteric Language Exploration
Demonstrating that programs can have aesthetic value beyond their function.
Computer Science Education
Illustrating compilation and interpretation concepts through unusual syntax.
Language Influence
Influenced By
Running Today
Run examples using the official Docker image:
docker pull esolang/splExample usage:
docker run --rm -v $(pwd):/code esolang/spl /bin/spl /code/hello.spl