esolang

Calculator

Arguments first, the command last, dots in between. Every value is a number in a named variable.

Ivan Homenko, 2016 · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello, World!

The idea

Ivan Homenko had the idea for Calculator, and the specification dates it to 2016. A statement is a row of arguments split by dots, with the command at the end and a ; after it, so a.b.+; adds b to a. Variables have names of any length, linefeed as well as 0, and hold numbers. There is no loop statement. A program marks labels and jumps to them, and four conditional jumps each pick one of two labels.

Read the story

The specification's table leaves out a.?;, which marks label a. Its truth machine uses it, and so does this implementation. Labels and variables have their own names, so 0 can be both.

The machine

StatementDoes
a.b.+; and - * / %Change variable a by variable b
a.5.v;Set a to 5; a.$.v; reads a number from the input
a.b.>;Copy b into a
a.#; a.@;Print a as a number, or as the character with that code
a.?; a.^;Mark label a; jump to it
a.b.c.!0; a.b.c.!1;Jump to b if a is 0 (or 1), else to c
a.b.c.d.!=; a.b.c.d.!==;Jump to c if a equals b (or does not), else to d
.!; .~;Clear the output; stop

The specification had a JavaScript implementation, so numbers are JavaScript numbers and / gives fractions. Variables start at 0, $ reads the next whole number and gives 0 at the end of the input, and # prints nothing after the number.

Example

The Hello, World! program gives every letter its own variable.

The Hello, World! program gives every letter its own variable.

The truth machine jumps to label 0 or label 1. On 1 it prints 1 and jumps back to its own label for ever.

Expected: 0

A count down from 3. It prints n, takes 1 away and jumps back to top until n is 0.

Expected: 321
Expected: 42

Patterns it teaches

Further

Stack-based

Write your own in Run Convert a program from Calculator

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: calculator.

Command line

shib run calculator -e 'in.$.v;in.#;' --input '42'
shib manual calculator

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/calculator.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org