A0A0
Every line is a queue. It gives up one command each time the run passes, and a loop is a line that copies itself.
Snowyowl, 2013 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Snowyowl made A0A0 in 2013. A program is a column of lines, and each line is a queue of commands. The run walks down the lines, and on each line it pops one command and runs it. A line that runs out of commands is empty, and an empty line ends the run.
Read the story
So a line lasts only as long as something feeds it. The language is named after the pair A0 A0. A0 appends a copy of what is left of its own line to itself, so a line that starts and ends with A0 keeps refilling itself. The specification says the name should be sung in a major third.
The machine
| Command | Does |
|---|---|
An | Append a copy of the rest of this line to the line n below |
Cn | Clear the line n below |
Gn | Go to the line n below instead of the next line |
Vn | Set the argument of the next command on this line to n |
Sn Dn Mn | Add n to the operand, subtract it, or multiply by it |
Ln | Set the operand to 1, -1 or 0 as it is above, below or equal to n |
I0 I1 | Read a number or a character into the operand |
On Pn | Print n as a number, or as the character n mod 256 |
The operand is the argument of the first V on the current line. When that V runs it hands its value to the command behind it, so V followed by O0 prints the operand. The program has endless empty lines above and below it, so a run that leaves it stops. A line that starts with > is where the run starts, which lets a debugger write its state out as a program.
Example
Two lines take turns.
Two lines take turns. M7 multiplies the 6 in V6, the second line sends the run back up, V42 turns O0 into O42, and the third visit prints it. Then the second line is empty.
A cat. Its first four lines start and end with A0, so they keep their commands and give up one each pass. The third line reads a character with I1, V passes it to P, and P prints it. The specification does not say what happens at the end of the input; in this implementation the read ends the run.
Patterns it teaches
- Self-modifying code: commands are used up as they run, and a loop is a line that copies itself.
- Code as data: the only variable is the argument of a
Vin the program.
Further
See also
Queue-based
Self-modifying
Write your own in Run Convert a program from A0A0
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: a0a0.
Command line
shib run a0a0 -e 'A0 A0
A0 C3 G1 G1 A0
A0 I1 V0 P0 A0
A0 A1 G-3 G-3 A0
G-3' --input 'cat'shib manual a0a0Source
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/a0a0.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org