Quiner
No instruction jumps back. To run code again, a program copies it into the data and waits for the data to become the code.
Umnikos, 2020 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 8 known programs · Test method
Run it
The idea
Umnikos made Quiner in 2020. There are two deques of characters, one for code and one for data, and each keeps its own pointer. When the code runs out, the two trade places and the data runs as code. The run halts only when both pointers stand at the end of their deques.
Read the story
So a loop is a program that writes a copy of itself into the data before it ends, which is how quines work. A branch is a character computed from the input that decides what the copy will skip.
The machine
Every instruction can have a decimal count in front. Without one the count is 1, or 2 for +.
| Instruction | Does |
|---|---|
a> | Append the next a characters of the code to the data and skip them |
a< | Append the a characters before the count to the data |
a. | Remove the last a characters of the data and print them |
a, | Append a input characters to the data |
a* | Remove the last a characters of the data |
a+ | Replace the last a characters of the data with their sum modulo 256 |
a// | Skip the next a characters; / with anything else skips only that one |
All seven change only the end of the data deque. Every other character does nothing.
Example
The second Hello World copies 3+14.
The second Hello World copies 3+14. to the data and skips the rest. Then the deques trade places. 3+ sums the last three characters of the old code, 6X|, to 266, which is 10 modulo 256, a line feed. 14. prints the 13 characters of the greeting and that line feed.
The quine prints nothing at first, then its first 4 characters, then its first 8. That makes 12.
The truth machine adds the input to @@@>. A 0 gives . and a 1 gives /, and that character lands after 9/ in the copied code. On 0 the code prints 0 and halts. On 1 it skips that part, prints 1 and appends its own last 12 characters, so it runs again forever.
A program can also read more of itself. 30, reads 30 characters, and when the code runs out they run as code.
Patterns it teaches
- Quine: every loop is a program that reproduces itself.
- Self-modifying code: the data a program builds is its next code.
Further
See also
Deque-based
Write your own in Run Convert a program from Quiner
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: quiner.
Command line
shib run quiner -e '30,' --input '13>Hello, world!
4>@@@J4+
14.
'shib manual quinerSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/quiner.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org