Immutable Brainfuck
No cell is ever changed. The tape only grows, by cells pushed in right after the pointer.
Rainwave, 2026 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Rainwave made Immutable Brainfuck in 2026, after Leafuck, to show computation that is monotonic and reversible at once. The tape holds bits, all 0 at the start. Nothing writes to a cell. 0 and 1 insert a new cell right after the current one and push the rest of the tape along, so the past is never lost and every step can be undone.
Read the story
The loop is turned around too. [ skips the loop when the cell is 1, not 0, and ] jumps back while the cell is 1. The specification shows it Turing complete by compiling Bitwise Cyclic Tag into five of the commands.
The machine
| Command | Does |
|---|---|
> < | Move the pointer |
0 1 | Insert a cell with that bit right after the current one |
[ | Jump past the matching ] if the cell is 1 |
] | Jump back to just after the matching [ if the cell is 1 |
. | Print the eight cells from here as a byte, highest bit first |
, | Read a byte and insert its eight bits after the current cell |
Example
Each group inserts eight bits after the pointer and walks over seven of them, then steps back six and…
Each group inserts eight bits after the pointer and walks over seven of them, then steps back six and prints from there. That leaves the pointer one cell further on than it started, ready for the next group. The specification calls it Hello World! but its eleven groups stop before the !.
The shorter one by Blashyrkh inserts all 112 bits after the first cell, so they end up reversed. The loop then prints seven of them at a time behind an inserted 0 and goes on while the eighth bit is 1.
The truth machine reads a character and looks at its lowest bit. On 0 it prints 0 once; on 1 it prints 1 forever.
Patterns it teaches
- Reversible computing: with nothing overwritten, each command has an inverse.
- Turing tarpit: five commands are enough for Bitwise Cyclic Tag.
See also
Immutable Brainfuck builds on Brainfuck.
Reversible computing
Brainfuck derivatives
Write your own in Run Convert a program from Immutable Brainfuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: immutable-brainfuck.
Command line
shib run immutable-brainfuck -e ',>.>>>>>>>[1]>[<<<<<<<<.>>>>>>>1>]' --input '0'shib manual immutable-brainfuckSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/immutable-brainfuck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org