VAR
Ten three-letter commands, and every value is a list of character codes.
machalvan · Turing complete: yes · ●○○ easy
Tested with 4 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
VAR, by machalvan on GitHub, has one statement per line: a command, then maybe a variable, then maybe a value. Underneath, a number and a string are the same thing. 65 is the list [65] and "AB" is [65, 66]. So OUT 65 prints A, and printing a number as digits takes STR first.
The machine
| Command | Does |
|---|---|
VAR x value | Set x; VAR x[i] value replaces one code |
INP x | Read a line into x |
OUT value [flag] | Print the codes as text, then a newline unless the flag is 0 |
INC x [n] DEC x [n] | Add or take away, default 1 |
INT x STR x | Digits to a number, a number to digits |
WHL x … END | Loop while the first code of x is not 0 |
CON x … END | Run once if the first code of x is not 0 |
A value is an integer, a "string" without escapes, a variable, or x[i], one code of a variable, which is 0 past its end. // starts a comment. The reference is var.py in github.com/machalvan/VAR.
Example
The second copies the counter, turns the copy into digits and prints it.
The second copies the counter, turns the copy into digits and prints it. The third finds the length of the input by reading codes until it meets the 0 past the end, then prints them backwards without newlines.
Patterns it teaches
- Turing completeness: unbounded lists and a while loop.
Further
- The reference interpreter, in Python
See also
Also in Turing tarpits
Write your own in Run Convert a program from VAR
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: var.
Command line
shib run var -e 'OUT 72 0
OUT 105'shib manual varSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/var.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language