Brainfork
Brainfuck with a ninth command, Y, that splits the running program in two.
Asger Ipsen, 2004 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Asger Ipsen made Brainfork in 2004. It keeps the eight brainfuck commands and adds Y, which forks the current thread. Every brainfuck program without a Y runs the same. Every Brainfork program is also a brainfuck program, because brainfuck ignores Y, but it then does something else.
Read the story
After a fork the two threads run the same code side by side. The parent and the child can tell themselves apart by one cell.
The machine
| Command | Does |
|---|---|
+ - < > . , [ ] | As in brainfuck |
Y | Fork. The parent's current cell becomes 0. The child gets a copy of the tape, moves one cell right and sets that cell to 1 |
Each thread has its own tape and pointer. Threads take turns, one command each per round, in the order they were born. The program ends when every thread has run off the end of the code. Cells are bytes that wrap.
Example
A brainfuck program that prints a sentence.
A brainfuck program that prints a sentence.
The same program with Y[-<] in front. The parent's cell becomes 0, so it skips the loop. The child's cell is 1, so it runs -< once and lands back on the same cell, now four commands behind. Both print the sentence, and their letters mix.
The specification leaves the timing open. This implementation always jumps back from ] to its [, which tests the cell again, and starts a child on the round after its birth. That reading prints exactly the mixed line the specification gives.
Patterns it teaches
- Turing tarpit: brainfuck's eight commands with one more.
- Nondeterminism: the output depends on how the threads take turns.
Further
See also
Brainfork builds on Brainfuck.
Concurrent programming
Brainfuck derivatives
Write your own in Run Convert a program from Brainfork
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: brainfork.
Command line
shib run brainfork -e '+++[>+++++<-]>[>+>+++>+>++>+++++>++<[++<]>---]>->-.[>++>+<<--]>--.--.+.
>>>++.<<.<------.+.+++++.>>-.<++++.<--.>>>.<<---.<.-->-.>+.[+++++.---<]>>[.--->]<<.<+.++.++>+++[.<][.]<++.'shib manual brainforkSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/brainfork.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org