Brainfault
Brainfuck with the conveniences bolted on, numbers out, equality tests and named subroutines.
2021 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
Brainfault keeps all eight brainfuck commands on a tape of byte cells that runs on without end both ways. It adds commands for things brainfuck has to build by hand. A cell prints as a number with one character. A block runs only when the cell holds one exact value. A loop can ask whether any input is left. A piece of code gets a name and can be called from anywhere, itself included.
The machine
| Command | Does |
|---|---|
+ - < > . , [ ] | As in brainfuck, on cells that wrap at 256 |
: ? | Print the cell as a decimal or a binary number |
/ ... | | Loop while some input is left |
!n( ... ) | Run the inside only if the cell holds n |
!~n( ... ) | Run the inside only if it does not |
$name{...} | Define a subroutine, wherever it stands |
*name* | Run a subroutine |
#...# | A comment, even if it holds commands |
The input queue is what is left of the input, and , gives 0 once it is empty.
Example
The cat prints each character as its code, with nothing between them.
The cat prints each character as its code, with nothing between them.
The truth machine on 0 prints the 0 once. On 1 the [.] prints 1 for ever.
div_two halves the cell with two equality tests, taking 2 at a time and counting the halves in the cell to the right. The program prints the input's code, then each half down to 0, a line each.
The decoder prints the character before each one and keeps spaces. A flag in the next cell stops a character that was already printed from being caught by a later test.
Its wrap from A to Z does not work as written. That branch adds 100 and takes 10 without clearing the cell first, so A comes out as byte 155. The encoder's z does the same and gives byte 219 instead of a.
Patterns it teaches
- Turing tarpit: brainfuck underneath, with the common idioms made into commands.
Further
See also
Brainfault builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from Brainfault
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: brainfault.
Command line
shib run brainfault -e '/ , : |' --input 'Hi'shib manual brainfaultSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/brainfault.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org