esolang

Unleash

Six instructions shuffle a stack that never runs out of empty lists. To run a list, you paste it back into the program.

Hakerh400, 2020 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 7 known programs · Test method

Run it

Expected: 011

The idea

Hakerh400 made Unleash in 2020, after Unlambda and Underload. The specification says it can be read as a stack language or as a string rewriting one. A program is a row of elements, and an element is a list in parentheses or one of six instructions. Each step takes the first element off the program. A list goes on top of the stack; an instruction runs.

Read the story

There are no numbers to compute with and no characters. Input and output are bits. The only way to loop is %, which puts a list back at the front of the program, so a loop is a list that copies itself before it runs.

The machine

The stack starts as endless empty lists, and index 0 is its top. An instruction can take numbers after it, split by |.

InstructionDoes
+x|y|zCopy y elements from index x to index z
-x|yRemove y elements from index x
~x|y|zMove y elements from index x to index z
*x|yWrap y elements from index x into one list
.xUnpack the list at x in its place; an instruction there stays only if the next input bit is 1
%xPut the list at x at the front of the program; an instruction there prints 0 for + - ~ and 1 for * . %

Without numbers + copies the top, - drops it, ~ swaps the top two and * wraps the top in a list. Every input bit is read after an extra 1, and past the end every bit is 0, so a program can tell where its input stops.

Example

To print a bit you need a bare instruction on the stack.

To print a bit you need a bare instruction on the stack. (+) pushes a list that holds +, . unpacks it, and % prints the + as 0.

The cat, invert and increment programs, each written on one line. The increment reads a binary number with its highest bit first.

Expected: 1011
Expected: 0100
Expected: 1100

The cat and the invert differ in one spot only. Where the cat has ((+)-1)((.)-1|2), the invert has ((.)-1)((+)-1|2). The specification also has a program that reverses the bits and one that decrements, and all five are included.

Patterns it teaches

Further

Also in Functional and concatenative

Write your own in Run Convert a program from Unleash

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run unleash -e '(
  ~((
    ((+)-1)
    ((.)-1|2)
    (+)..%1.%+%
  )-1|2)
  (+)..%1%
)+%' --input '1011'
shib manual unleash

Source

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

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

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