Marbelous
A marble run. Byte-valued marbles fall down a board of two-character devices, all at once, tick by tick. Whatever falls off the bottom is printed.
cjfaure and the Code Golf Stack Exchange community, 2014 · Turing complete: unknown · ●●○ moderate · esolangs.org
The idea
Marbelous was designed in 2014 by members of the Code Golf Stack Exchange community; the original idea is credited to cjfaure. The name is "marble" plus "marvelous".
Read the story
Think of a Rube Goldberg machine. A program is a board of cells, each two characters wide. Marbles, each holding a byte, fall one cell per tick. Devices in the cells change them, push them sideways, copy them, destroy them or hold them back. Marbles that fall off the bottom of the main board are printed as characters.
Unlike most 2D languages there is no single instruction pointer. Every marble moves in the same tick, so a board is closer to a small physical simulation than to a program counter. Extra boards act as functions; their inputs and outputs are marbles too.
The machine
A board is a grid of two-character cells. .. is empty. Each tick, every free marble falls one cell; two marbles that land in the same cell merge, and their values add.
| Cell | Does |
|---|---|
00–FF | A hex literal: a marble with that value appears here on the first tick |
.. | Empty: marbles fall through |
++ -- | Add or subtract one |
+n -n | Add or subtract n |
>> << ~~ | Shift right, shift left, invert the bits |
\\ // | Push the marble right, or left |
/\ | Clone: a copy goes left and a copy goes right |
\/ | Trash: the marble disappears |
=n >n <n | Let the marble fall only if it equals, exceeds, or is below n; otherwise push it right |
@n | Portal: the marble comes out at another @n |
&n | Synchroniser: hold marbles until every &n on the board has one, then release them together |
?n ?? | Random marbles |
]] | Read a byte of input |
}n {n | A board's nth input and output |
!! | End this board now |
A board stops when all its outputs are filled, when !! is hit, or when no marble moves in a tick. The program ends when the main board stops.
Example
Print Hi!.
Print Hi!. Each column starts with a marble one less than the letter to print, which then falls through ++:
47 68 20
++ ++ ++
Trace:
- Three marbles appear in the top row, with values 0x47 (
G), 0x68 (h) and 0x20 (space). - They fall onto the
++cells and become 0x48 (H), 0x69 (i) and 0x21 (!). - All three fall off the bottom in the same tick, so they are printed left to right:
Hi!. - Nothing is left to move, so the board, and the program, stop.
This was traced by hand from the specification draft, so the tick of each step is not exact. There is no Marbelous implementation here.
Patterns it teaches
- Two-dimensional control flow: gravity is the default direction; devices bend it.
- Nondeterminism:
?ndrops random marbles. Everything else is fully synchronous and deterministic, which makes timing, not order, the hard part. - Turing completeness: despite recursion between boards, Marbelous is believed not to be universal. Its memory is the marbles on finite boards, which makes it look like a linear bounded automaton. Nobody has settled it either way, hence
tc: unknown.
Try this
- Change the example to print
Heyusing+ninstead of++. - Use
/\(clone) to printAAfrom a single41marble. - Hard: use
=nto build a board that prints only the input bytes equal toa.
Further
- esolangs.org/wiki/Marbelous
- The spec draft and Python interpreter in the marbelous-lang organisation on GitHub.
- Related: Funciton, Befunge.
See also
Two-dimensional languages
Source esolangs.org (CC0) · Edit on esolangs.org