esolang

Calcutape

A pocket calculator on a stack. Every number is built from single digits, and one command can turn the program around.

Darkrifts, 2016 · Turing complete: unknown · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello World!

The idea

Darkrifts made Calcutape in 2016 to work out sums on a stack. A digit pushes itself, so any bigger number has to be calculated. 100 is 52*_*, five times two, duplicated and squared. Text is a row of character codes built this way and printed one by one with @.

Read the story

The only control flow is #. It looks at the top of the stack and leaves it there. On 0 the program turns around and runs backwards; on a positive N it skips the next N commands.

The machine

CommandDoes
0 to 9Push the digit
+ *Add or multiply the top two
- /The top minus, or over, the one below it
:Push a number from 1 to 999
% @Print the top as a number or as a character
| _ $Swap, duplicate, drop
&Pop N and copy the Nth number from the top
#0 turns around, N skips N commands
VRead a character
?End the program
( ... )A comment, closed by any of ) ] }

The program ends when it runs off the right end. At the left end it turns around.

Example

The Hello World program builds twelve character codes, the last letter first, and prints them all at the end.

The Hello World program builds twelve character codes, the last letter first, and prints them all at the end.

The 5 makes # skip five commands, so the run lands on the 6. Six % print the stack from the top down.

Expected: 098765

A key press becomes its digit when 48 is taken away, and nine squared is 81.

Expected: 7
Expected: 81

Patterns it teaches

  • Stack machines: every value is calculated on the stack from single digits.

Further

Stack-based

Write your own in Run Convert a program from Calcutape

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run calcutape -e 'V@ (Only outputs once)' --input 'a'
shib manual calcutape

Source

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

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

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