esolang

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

Expected: Hello World!

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

CommandDoes
10 11 12 14 15a + b, a - b, a * b, a // b, a % b
16 17 18 19Increment, decrement, 1 if negative, factorial
20 n or *nPush n; $k instead of n copies the item k below the top
21 22 23 26 27Toggle stacks, swap, pop, duplicate, clear
24 25Move the top to the other stack, or back
30 31Print a number, or a character
32 33Print the stack as numbers or as a string, and empty it
34 35 36Read an integer, a character, or a line of characters
40 41Run the next command only if the top is not 0, or only if it is 0
42Jump to the command with that index
*f 44 m code 44Define function f on one line
f 45 x y ... 45Map 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.

Expected: 2 3 4 5 6 7 8 9 10

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.

Expected: 0

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.

Expected: 66

Patterns it teaches

Further

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 numbers

Source

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