ResPlicate
A list of numbers that reads two from its front and copies a piece of itself to its back.
Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
A ResPlicate program is nothing but integers in a queue. There are no commands. Each step takes two numbers, x and y, from the front, then takes the next x numbers and puts that piece at the back y times. A piece that is copied twice grows the program; a piece copied zero times is gone. It works like a tag system whose rules are written in the data itself.
The machine
| Front of the queue | Does |
|---|---|
x y with x above 0 | Take the next x numbers, append them y times |
0 y with y 0 or more | Print the byte y |
0 y with y below 0 | Read a character c and append c + y + 1 |
The I/O rows belong to the -i flag, which Try It Online passes and this implementation always assumes. An empty queue gives 0s. The run ends when the queue is empty, or when it comes back to a state it was in before, since then it would loop forever. That check is off for a program that holds a negative number as written. The reference is resplicate.py in github.com/TryItOnline/ResPlicate.
Example
The second copies a 0 to the back, then 0 -1 reads A and appends 65, leaving 0 65 to print it.
The second copies a 0 to the back, then 0 -1 reads A and appends 65, leaving 0 65 to print it. The third prints !, then 4 2 copies 0 33 4 2 twice. That is the program it started with, so the run stops.
Patterns it teaches
- Self-replication: code that copies itself is the only control flow.
- Tag systems: read at the front, write at the back.
Further
See also
Also in Rewriting
Write your own in Run Convert a program from ResPlicate
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: resplicate.
Command line
shib run resplicate -e '1 1 0 0 -1' --input 'A'shib manual resplicateSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/resplicate.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org