BrainIf
Brainfuck's tape, where every line first asks what the cell holds.
VilgotanL, 2021 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
VilgotanL made BrainIf in 2021 on the same tape as brainfuck. There are no brackets. Each line names one number and one action, and the action happens only when the current cell holds that number. A goto to a line number is the only way back.
Read the story
So every value is spelled out. To put 72 in a cell a program needs 72 lines, if 0 increment, if 1 increment and so on up to if 71 increment. Bangyen's Hello, world! on the specification has 648 instructions on 660 lines and prints 13 characters.
The machine
| Line | Does, when the cell holds n |
|---|---|
if n increment | Add 1 to the cell |
if n move right if n move left | Move the pointer |
if n goto line | Continue at that line, counted from 1 |
if n input | Read a character into the cell |
if n output | Print the cell as a character |
Empty lines do nothing but keep their number. Any other line is an error.
Example
The first program reads a character and prints it only if it is an E, code 69.
The first program reads a character and prints it only if it is an E, code 69.
With a goto it keeps going. Each E is printed, then the pointer moves to a fresh cell holding 0, and line 4 sends it back to line 1 to read the next character. The x is not 69 and not 0, so nothing acts on it and the program runs off its end.
Patterns it teaches
- Turing tarpit: six guarded commands and nothing else.
- Tag systems: the specification shows BrainIf is Turing complete by turning cyclic tag systems into it.
Further
See also
BrainIf builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from BrainIf
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: brainif.
Command line
shib run brainif -e 'if 0 input
if 69 output' --input 'E'shib manual brainifSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/brainif.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org