Foldy
A 2D language that starts out as a single line, and folds itself into a grid as it runs.
Squareroot12621, 2025 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Squareroot12621 made Foldy in 2025. Its code begins as one row. When the instruction pointer meets { or } the rest of the code folds counterclockwise or clockwise, and the program becomes two dimensional. With fold mode turned off by #, the same two characters only turn the pointer.
Read the story
The specification does not say how a fold lays out the rest of the code, or how ] counts its n. This implementation leaves both out. It runs the row unfolded, and a fold or a ] stops the run with an error. Everything else is supported.
The machine
| Char | Does |
|---|---|
0 to 9 | Push a digit |
+ - * : | Arithmetic on the top two; : divides and blows up on 0 |
< > ^ v | Point the pointer |
/ \ | _ | Bounce the pointer |
$ | Skip the next instruction if the top is above 0 |
? | Replace the top with a random number below it |
! . | Print the top as a character or as a number |
; , | Read a character or a number |
& ~ [ | Duplicate, pop, move the top to the bottom |
{ } | Fold the rest of the code, or turn when fold mode is off |
# | Toggle fold mode |
@ | End |
The row wraps around at both ends.
Example
The truth machine has no @ it can reach on 0.
The truth machine has no @ it can reach on 0. It prints the 0, then divides 0 by 0 and blows up. On 1 the two $ skip the @ and the , after the wrap, and it prints 1 forever.
The XKCD random number draws a number below 9 and prints 4, chosen by fair dice roll.
Patterns it teaches
- Two-dimensional control flow: a line of code that becomes a grid.
- Stack machines: every value lives on one stack.
Further
See also
Two-dimensional languages
Cell-based
Write your own in Run Convert a program from Foldy
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: foldy.
Command line
shib run foldy -e ',,+.@' --input '3
4
'shib manual foldySource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/foldy.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org