Forbin
Bits and functions and nothing else. An if is a for loop from !c to c.
PythonshellDebugwindow, 2020 · Turing complete: with unbounded memory · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
PythonshellDebugwindow made Forbin in 2020. Its only values are bits and functions, and its only control flow is the call and the for loop. A for loop walks a list of values or a range of bits. A range from 1 to 0 runs no times, so a loop from !c to c is an if. When c is 1 it runs twice, once with 0 and once with 1, so the specification's own if returns from inside the loop.
Read the story
Input and output are bits as well. in gives one bit of input at a time, the highest bit of each byte first, and out takes eight bits and writes them as a byte. A program defines main, which runs. The specification counts Forbin as a bounded-storage machine, since every variable holds a single bit.
The machine
| Form | Does |
|---|---|
f a, b { ... } | Define a function with parameters a and b |
a, b = x, y; | Assign; one value for many names is worked out once per name |
f x, y; and (f x, y) | Call, as a statement or as a value |
for v:(0, 1, *) { ... } | Run once per value; * is 0 and then 1 |
for (v, w):((0, *), (1, 1)) { ... } | Run once per tuple |
for v:a..b { ... } | Run from a up to b, so 1..0 runs no times |
return x; | Leave the function with x, 0 if there is none |
!x | 1 if x is 0, else 0 |
{ ... } and (a @ { ... }) | A function as a value |
A call needs at least one argument, so the specification passes 0 to a function that takes none. Missing arguments are 0. A loop variable has to exist before the loop, and _ throws its value away.
Example
The Hello World writes each letter as its eight bits.
The Hello World writes each letter as its eight bits.
The truth machine reads eight bits and writes them back. The last of them is the lowest bit, so the loop from !h to h calls loop only on an odd byte such as 1.
The equality test flips a bit once per pass of a range loop. From 1 to 1 it runs once and gives 1, from 0 to 1 it runs twice and gives 0, and from 1 to 0 it does not run.
The cat and its while function both use the loop from !c to c without a return, so their body runs twice. The cat calls main again twice for each byte that is not 0. In this implementation in gives 0 at the end of input, and on abc the cat prints abc and then four zero bytes.
The specification leaves a few things open. In this implementation the statements outside functions run first and then main, and the ; before a } may be left out, which the cat needs.
Patterns it teaches
- Turing tarpit: one kind of value, one bit wide, and one loop.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from Forbin
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: forbin.
Command line
shib run forbin -e 'main {
a,b,c,d,e,f,g,h = (in 0);
out a,b,c,d,e,f,g,h;
for _:!h..h {
loop 0;
}
}
loop {
out 0,0,1,1,0,0,0,1;
loop 0;
}' --input '0'shib manual forbinSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/forbin.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org