Takeover
Standard input is appended to the program before it runs. The input is code, and the empty program is a self-interpreter.
ais523, 2016 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
ais523 made Takeover in 2016 around that one idea, and designed the rest of the language to fit it. It is close to Splinter and to Forth.
Read the story
The program is a stack, as in Underload. Commands are popped from the front, and many of them push new commands back. Any octet can be redefined, and it keeps all its definitions, numbered from 1. An octet with a number is a snapshot, so a with a 4 always means the fourth definition of a, whatever the latest one is. The only output is the active definition, the list of snapshots being built, printed when the program runs out of commands.
The machine
Every octet starts with three built in definitions. A snapshot without a number uses its octet's latest definition.
| Number | Does |
|---|---|
| 1 | Move the active definition into a new definition of this octet |
| 2 | Append this octet, numbered with its count of definitions, to the active definition |
| 3 | Push . with a 4, then the octet one below this one |
| 4 and up | Push that definition onto the front of the program |
Seven octets have a different definition 3. Six of them change the commands that run after them.
| Command 3 | Does |
|---|---|
+ - | The next command's number is one higher, one lower |
> < | The next command's number is 1, its latest |
, | The next command is the octet above it, with number 2 |
[ | Every command gets number 2 until the ] that matches |
] | Nothing |
So [text] appends the text to the active definition, and >x makes it a new definition of x. Using a definition that does not exist crashes the program, and a crash prints nothing.
Example
That is only right on empty input, since the input runs after it.
That is only right on empty input, since the input runs after it. The hello world builds a setup with [...], makes it + number 4 with >+ and runs it with +. The setup gives + - [ ] < > , . empty definitions, so every octet of the input either does nothing or counts down to one that does. The text that follows is appended with number 3, which still means the built in commands.
A bracket in the text would close [ too early. , escapes it with the octet below, so ,\ appends ].
The cat ends its program in the [ state, so every octet of the input is appended to the active definition. Before that it redefines ]. An unmatched ] ends the state and runs its latest definition, which appends a ] and starts the state again.
The specification also compiles Splinter into Takeover, which shows it is at least a push down automaton. Whether it is Turing complete is open.
Patterns it teaches
- Self-modifying code: every command can be redefined while it runs.
- Code as data: the input is appended to the program.
- Stack machines: the program itself is the stack.
Further
See also
Also in Functional and concatenative
Write your own in Run Convert a program from Takeover
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: takeover.
Command line
shib run takeover -e '[Hello, world!]'shib manual takeoverSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/takeover.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org