esolang

Stæck

A stack of bits that can grow but never shrink, and commands that either work or fail.

TuxCrafting, 2019 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: cat

The idea

TuxCrafting made Stæck in 2019 to run a deterministic nonerasing stack automaton. The program gets a read-only string of bits, and it keeps a stack of bits it may push onto but never pop. Both have a pointer that moves one place at a time. There are no numbers and no jumps. Every command either succeeds or fails, a failure ends the block it is in, and a loop goes round until its body fails.

Read the story

That is enough. The specification proves it Turing complete with a Bitwise Cyclic Tag interpreter of 83 characters.

The machine

CommandDoes
[...]Run the block, then go on whatever happened
{...}Run the block until it fails
< >Move in the input bits; fail at the end
^ vMove in the stack; fail at the end
!Fail

A mover takes a bit from a source, may flip it with @, and hands it to a destination.

SourceBitDestinationDoes
#under the input pointer&Push it on the stack
$under the stack pointer.Write it
,next bit of the byte input;Fail on 0
' "0 and 1:Fail on 1

Bytes are read and written a bit at a time, the least significant bit first, so eight writes make one character. The input bits come from the input's first line, and the bytes after its line feed are the byte input. A program that fails as a whole ends as failed.

Example

The cat reads and writes bits until the input runs out.

The cat reads and writes bits until the input runs out. Its bitstring line is empty.

The truth machine writes the input bit with the seven bits that make it a digit, and stops on 0.

Expected: 0

The Collatz program takes a number in unary and prints every step of its sequence in unary, one per line. From 3 it takes seven steps.

Expected: 111 1111111111 11111 1111111111111111 11111111 1111 11 1

The matcher for strings of n ones then n zeros succeeds on 1100 and 111000 and fails on 110 and 1010. It prints nothing, so only the end of the run tells.

Patterns it teaches

Further

Stack-based

Write your own in Run Convert a program from Stæck

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: st-ck.

Command line

shib run st-ck -e '{,.}' --input '
cat'
shib manual st-ck

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/st-ck.js

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

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