CONTAIN
Boxes of numbers, and arithmetic that waits until the pointer moves.
2025 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
CONTAIN is from 2025. Memory is a row of boxes, each holding a number, in the order they were made. The strange part is the binary operations. + does not add yet. It waits until the box pointer next moves, and then adds the box the pointer lands on to the box it left. So +> adds the next box, +< the previous one, and $+& adds a box to itself.
Read the story
Division by 0 deletes the box, and the program ends when no box is left. That is the only way most programs stop.
The machine
| Command | Does |
|---|---|
[n] [] | Make a box holding n, or 0 |
"text" | Make one box per character, holding its code |
> < | Move to the next or the previous box |
$ & | Save the pointer's place; go back there |
( ) | Save the place in the program; jump back there |
x | Make the next ) or & do nothing if the box holds 0 |
+ - * / % | When the pointer moves, work the box it left with the box it lands on |
= @ | When the pointer moves, copy that box's value in; swap the two |
! ? | Print the box as a number; as a character |
^ | Make a box holding 0 right after this one |
: ; | Read a number; read a character |
# | Comment to the end of the line |
Moving past the last box wraps to the first. Numbers print with nothing between them.
Example
The truth machine reads a number and prints it.
The truth machine reads a number and prints it. Then $/& divides the box by itself. On 0 that deletes the only box and the program ends. On 1 the loop (!) prints 1 forever.
The factorial keeps 1, n and 1 in three boxes. Each pass multiplies the first box by n and takes 1 off n, until x sees 0 and lets the program fall through to !. The last loop then divides every box away.
The Hello World, []"Hello, World!">(?/&>), prints a letter and then goes back to the 0 box with &, so the letter divides by 0 and disappears. The next > lands on the next letter. Once the letters are gone, the pointer wraps onto the 0 box, which prints as a NUL byte before 0 divided by 0 deletes it.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from CONTAIN
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: contain.
Command line
shib run contain -e '[]:!$/&(!)' --input '0'shib manual containSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/contain.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org