3var
Three variables, one letter per command, and Deadfish's squaring to make numbers grow fast.
LuaGeek2412 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 5 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
LuaGeek2412 made 3var to be as capable as other esolangs while staying easy to write an interpreter for. It grew out of Deadfish, whose accumulator can only be incremented, decremented, squared and printed. 3var has two such accumulators, A and B, and a third variable R for results.
Read the story
Arithmetic always combines A and B and puts the answer in R; > and < move it back. Conditions compare A with B. That is enough for loops, conditionals and character input.
The machine
| Code | Does |
|---|---|
i d s | A plus one, minus one, squared |
a k m | The same for B |
+ - * / ^ | R = A+B, A−B, A×B, A÷B, A to the power B |
> < | Copy R into A or into B |
x 0 | Absolute value of A or B |
r @ # e | Zero all, A, B or R |
p o w | Print A, B or R as a number |
P O | Print A or B as a character |
' " | Read a character or a number into R |
u(…) U(…) =(…) | Run once if A>B, A<B, A=B |
\|[…] _[…] \[…] | Loop while A>B, A<B, A=B |
f[…] F[…] | Loop A times or B times |
{…} | Loop forever |
$ ~ ` | Block comment, line comment, skip one character |
The variables hold integers of any size. Any other character is an error, so prose has to go in comments; whitespace is allowed.
Example
The first is a countdown, from 3.
The first is a countdown, from 3. While A is greater than B, which is 0, print A and take one off. The second builds 101 with iii s i s i, which is 3, 9, 10, 100, 101, prints e, sets B to 2 and runs its loop twice. The third reads 14 into R, moves it to B and multiplies by 3.
Patterns it teaches
- Counter machines: two unbounded counters, increments and a test are enough.
- Turing completeness: the specification notes it is Turing complete exactly when the variables are unbounded.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from 3var
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: 3var.
Command line
shib run 3var -e '"<iii*w' --input '14'shib manual 3varSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/3var.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org