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
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 |.
| Instruction | Does |
|---|---|
+x|y|z | Copy y elements from index x to index z |
-x|y | Remove y elements from index x |
~x|y|z | Move y elements from index x to index z |
*x|y | Wrap y elements from index x into one list |
.x | Unpack the list at x in its place; an instruction there stays only if the next input bit is 1 |
%x | Put 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.
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
- Stack machines: every instruction names stack positions.
- Code as data: a list is data on the stack until
%makes it program again. - String rewriting: the program text itself is what grows and shrinks as it runs.
Further
See also
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 unleashSource
- 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