VD3
One command. A variable becomes the sum of three things, and that is all a program ever does.
2009 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
VD3 dates from 2009 and has a single command, W<-X^Y^Z, which sets W to X + Y + Z. Each term is a whole number or a variable. Everything else comes from three special variables. Setting PC jumps, reading IN takes a character from the input, and setting OUT prints one. A jump to a negative position ends the run.
Read the story
VD3 2.0 adds more variables and the ... mark. A command written ...W<-X^Y^Z also fills every empty position after it, so a jump far past the last line still lands on something. That turns a sum into a branch, and the specification uses it to build any two-counter machine, which makes VD3 2.0 Turing complete.
The machine
| Variable | Read | Set |
|---|---|---|
A B C D E | Its value, 0 at the start | Store |
PC | The position of this command | Jump there; below 0 stops |
IN | The code of the next input character | Not allowed |
OUT | The last code printed | Print that character |
Commands are counted from 0, one per line. Running past the last line stops the run, unless a ... command fills the positions there. Any name of letters is a variable, since the specification's own example uses F, and IN gives -1 at the end of the input.
Example
The jump skips position 1 and prints only the B.
The jump skips position 1 and prints only the B.
The jump if zero adds the input's code to 7 and takes away 48. A 0 lands on 7, which jumps to the 5 saved in E and prints A. A larger digit lands past 7, where the ... command jumps back to the 3 saved in F and prints B.
The cat prints each character and jumps back to 0. At the end of the input IN gives -1, which is no character, so the run stops there with an error.
Patterns it teaches
- One instruction: a sum into a variable, where the variable decides what the sum means.
- Counter machines: the proof runs any two-counter machine.
Further
See also
OISC
Write your own in Run Convert a program from VD3
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: vd3.
Command line
shib run vd3 -e 'OUT<-65^0^0'shib manual vd3Source
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/vd3.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org