Cable
A row of blocks, run from the left. A block can delete, copy or add the blocks in front of it, and that is the only way to loop.
RainbowDash, 2026 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 8 known programs · Test method
Run it
The idea
RainbowDash made Cable in 2026. A program is a row of blocks in square brackets. The leftmost block runs and is gone, then the next one. Some blocks only print or set a variable. The others work on the row itself. Delete throws away the block in front, If does the same when its test is false, Duplicate copies the block in front and Append puts new blocks at the front.
Read the story
Cable has no loop. A loop is a block that keeps putting its own body back in front of itself.
The machine
| Block | Does |
|---|---|
[A = 5] | Set a variable, or change it with += -= *= //= %= |
[Print "text" + A] | Print the parts between the + signs, one after the other |
[Newline] | Print a line feed |
[Delete] | Remove the block in front |
[If A == 5] | Remove the block in front if the test is false |
[Duplicate 5] | Make the block in front appear 5 times |
[Append [..][..]] | Put these blocks at the front of the row |
[Integer A] [Upper A] [Lower A] | Turn a string into a number, or change its case |
Values are whole numbers and strings. A test gives 1 or 0, and it is false when it gives 0 or an empty string. Print joins the text of each part between its + signs, so with A and B both 5, [Print A+B] prints 55 and [Print (A+B)] prints 10.
Example
The loop.
The loop. [Duplicate] doubles the Append block, and the first copy puts the body in front. The body prints, counts and ends with [Duplicate] again, so the copy that waits is doubled for the next round. When A reaches 10 the test is true, and [Delete] removes that last [Duplicate]. The one copy left prints 10 and the row runs out.
The specification does not say how many copies [Duplicate] makes without a number. Two is the count that makes this loop stop at 10, so this implementation makes two.
Patterns it teaches
- Self-modifying code: every loop and branch deletes, copies or adds blocks of the program while it runs.
Further
See also
Also in Rewriting
Write your own in Run Convert a program from Cable
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: cable.
Command line
shib run cable -e '[Delete][Print "Hello world"]'shib manual cableSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/cable.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org