omnifuck
Brainfuck with many brains. Each brain remembers the commands it was given, so a loop left open is a function.
2014 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
omnifuck adds function calls to brainfuck without adding a call command. There is a row of brains, each with its own tape and its own list of commands. The program is read one command at a time, and each command is appended to the list of the brain that is active, then run. A brain that is called again carries on in its own list, so a ] there jumps back into commands it was given long before.
The machine
The eight brainfuck commands work as usual on the active brain. Three are new.
| Command | Does |
|---|---|
! | Switch between running commands and only appending them |
} | Make the brain n places to the right active, n being the cell under the pointer |
{ | The same to the left |
When control moves, the cell under the pointer and its two neighbours are copied to the same places around the new brain's pointer. That is how a call takes its arguments and a return gives its results.
A function is written in three parts. Between two ! its body is appended to a brain without running, starting with a [ that stays open. A { after it returns to the caller. Later the caller moves to that brain with }, and a ] appended there jumps back to the open [. The body runs, reaches the { and returns, and the brain waits at its ] for the next call.
Example
The program keeps one function in brain 1 that adds 48 and prints, and one in brain 2 that prints a line feed.
The program keeps one function in brain 1 that adds 48 and prints, and one in brain 2 that prints a line feed. Brain 0 calls them six times.
A smaller one. Brain 1 gets a function that prints the cell right of its pointer. Brain 0 puts 65 there, calls it, adds 1 and calls it again.
The program needs one thing it does not say. A tape starts at cell 0, and < there stays put, because the function's own < < < runs again after its body on every call.
Patterns it teaches
- Turing tarpit: brainfuck's eight commands, with calls made from nothing but where commands are stored.
Further
See also
omnifuck builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from omnifuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: omnifuck.
Command line
shib run omnifuck -e '+}![> >+< <!{}]'shib manual omnifuckSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/omnifuck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org