Whitespace, short for Whitespace Programming Language, is an esoteric programming language in which only spaces, tabs, and linefeeds have syntactic meaning. It is primarily used for experimental purposes, puzzles, and educational exploration of language design, rather than conventional application development. Developers can write Whitespace programs using any plain text editor and execute them with interpreters available at official repositories such as the Whitespace GitHub project.
Whitespace exists to explore unconventional approaches to programming language design and to challenge assumptions about code readability and syntax. Its design philosophy emphasizes minimalism, invisibility of characters, and separation of program logic from visible text. By using only whitespace characters for instructions, the language highlights the distinction between syntax and presentation, and encourages thinking about computation in nontraditional ways.
Whitespace: Basic Stack Operations
The core of Whitespace is a stack-based architecture where operations manipulate an abstract stack of integers. Push, pop, and arithmetic operations form the foundation of computation.
[Space][Space][Tab][Space][LF] ; Push 1
[Space][Space][Tab][Tab][LF] ; Push 2
[Tab][Space][Space][LF] ; Add top two stack items
[LF][LF][LF] ; End programThis snippet demonstrates pushing values onto the stack, performing addition, and terminating the program. Stack-based operations are encoded entirely with space, tab, and linefeed, making the source invisible in conventional editors. The approach is analogous in concept to low-level operations found in assembly or stack-oriented languages like Forth.
Whitespace: Flow Control
Whitespace supports labels, unconditional and conditional jumps to control execution flow based on stack or heap values.
[LF][Space][Space][Label] ; Define label
[LF][Tab][Space][Label] ; Jump to label if top stack item is zero
[LF][Tab][Tab][Label] ; Jump if top stack item is negative
[LF][LF][LF] ; End programLabels and conditional jumps allow branching logic, enabling the implementation of loops and decision structures. Flow control in Whitespace mirrors conditional branching found in assembly or virtual machine bytecode, demonstrating Turing-completeness despite its minimal syntax.
Whitespace: Heap Access
Whitespace provides a heap for storing and retrieving integers at arbitrary addresses, complementing stack operations for persistent data.
[Tab][Space][Space] ; Store value from stack into heap
[Tab][Space][Tab] ; Retrieve value from heap onto stackHeap operations extend the computational model beyond simple stack manipulation, enabling more complex algorithms and data structures. This allows Whitespace to support programs of significant logic complexity, similar in concept to memory operations in low-level languages like Assembly.
Whitespace: Input and Output
Whitespace can read and write characters or integers to standard input and output, enabling interaction with the environment and external data.
[Tab][LF][Space][LF] ; Output top stack item as character
[Tab][LF][Tab][LF] ; Output top stack item as number
[Tab][LF][LF][Space] ; Read character into heap
[Tab][LF][LF][Tab] ; Read number into heapInput and output instructions allow Whitespace programs to produce visible results and interact with users, despite the invisible source code. This demonstrates the language’s functional completeness in performing real computations.
Overall, Whitespace provides a minimalistic and esoteric environment for stack- and heap-based computation using only invisible characters. When studied alongside Forth, Assembly, Brainfuck, or other esoteric languages, it reveals fundamental principles of computation and program flow. Its unique syntax, focusing entirely on space, tab, and linefeed, makes Whitespace a fascinating experiment in programming language design and Turing-complete computation.