esolang

shortstack

A Turing machine whose only output is its own tape, printed after every character.

mmph · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: [0]

The idea

mmph made shortstack so that its interpreter would be short, not its programs. The specification says it should not be used for code golf. The whole interpreter is 19 lines of Python, and it runs five commands on a tape of bits. There is no input and no way to print a character. After every character of the source, a command or not, the interpreter prints the whole tape as a Python list.

The machine

CommandDoes
< >Move the pointer; > past the end adds a 0
,Flip the cell between 0 and 1
[Jump to the partner ] if the cell is 0
]Jump back to the partner [ if the cell is not 0

This implementation keeps what the interpreter does at the edges. Brackets are paired first in, first out, so in [[]] the outer [ pairs with the inner ]. Moving left from the first cell makes the pointer -1, and Python reads that as the last cell.

Example

The truth machine is ,[] on 1 and [] on 0, as the specification has no input.

The truth machine is ,[] on 1 and [] on 0, as the specification has no input. On 1 it prints [1] forever. On 0 the [ jumps over the loop and the tape is printed once.

The pointer goes left of the first cell, and the last , flips the last cell.

Expected: [1] [1, 0] [1, 1] [1, 1] [1, 1] [1, 0]

The "Hi" program has 31 characters and prints 31 tapes, the last one [0, 1, 1, 0, 1, 0, 0, 1].

Patterns it teaches

Further

Cell-based

Write your own in Run Convert a program from shortstack

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run shortstack -e '[]'
shib manual shortstack

Source

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

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

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