Numbers
Every command is a number, and so is every argument.
Xorol, 2021 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
Xorol made Numbers in 2021. Its gimmick is that almost every command is a number. The first digit says the group, 1 for arithmetic, 2 for the stack, 3 for input and output and 4 for control flow, and the second picks the command. So 30 prints and 26 duplicates, and a program reads like a list of figures.
Read the story
There are two stacks, a main one and a control stack, and 21 toggles between them. The specification says most commands starting with 4 use only the control stack, but its own examples run them on the main stack, so every command uses the selected one.
The machine
| Command | Does |
|---|---|
10 11 12 14 15 | a + b, a - b, a * b, a // b, a % b |
16 17 18 19 | Increment, decrement, 1 if negative, factorial |
20 n or *n | Push n; $k instead of n copies the item k below the top |
21 22 23 26 27 | Toggle stacks, swap, pop, duplicate, clear |
24 25 | Move the top to the other stack, or back |
30 31 | Print a number, or a character |
32 33 | Print the stack as numbers or as a string, and empty it |
34 35 36 | Read an integer, a character, or a line of characters |
40 41 | Run the next command only if the top is not 0, or only if it is 0 |
42 | Jump to the command with that index |
*f 44 m code 44 | Define function f on one line |
f 45 x y ... 45 | Map f onto each number |
~ | End the program |
The specification does not say which of a and b is the top; a is. This implementation leaves out true division (13), modules and namespaces.
Example
The Hello World maps 20, push, onto the codes of the text and prints the stack as a string.
The Hello World maps 20, push, onto the codes of the text and prints the stack as a string.
Mapping increment over 1 to 9 leaves 2 to 10, which 32 prints.
The truth machine reads a number and keeps two copies under the one it prints. On 0, 41 runs the ~ and the program ends. On 1 it skips it, pushes 2 and jumps back to command 2, the second 26, forever.
A function is defined on one line, such as 6, which prints a 6. The specification does not say how to call one, so its name runs it.
Patterns it teaches
- Stack machines: two stacks, one in use at a time.
Further
See also
Stack-based
Write your own in Run Convert a program from Numbers
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: numbers.
Command line
shib run numbers -e '36 33' --input 'cat'shib manual numbersSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/numbers.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org