Brainlove
Brainfuck with an "if zero" loop, a break and one spare cell to keep a value in.
Turing complete: yes · ●○○ easy · esolangs.org
Tested with 5 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Brainfuck can only loop while a cell is not 0, and it has no way to leave a loop early. Brainlove adds both. ( and ) loop while the cell is 0, and ~ breaks out of the innermost loop. Together they give a plain if. [stuff~] runs stuff once when the cell is not 0, and (stuff~) runs it once when it is.
Read the story
Two more commands come from Extended Brainfuck Type I. $ copies the cell into a storage cell and ! copies it back, so a value can travel along the tape without a loop.
The machine
A tape of byte cells that wrap at 256, growing both ways, a pointer and one storage cell.
| Command | Does |
|---|---|
+ - < > . , [ ] | As in brainfuck |
( | If the cell is not 0, jump past the matching ) |
) | If the cell is 0, jump back to the matching ( |
~ | Jump past the end of the innermost loop around it |
$ | Copy the cell into storage |
! | Copy storage into the cell |
Reading past the end of the input gives 0. Every other character is a comment.
Example
The second program reads two letters and swaps them through a third cell, the way the specification shows it.
The second program reads two letters and swaps them through a third cell, the way the specification shows it. $ and ! move each value in one step.
Patterns it teaches
- Turing tarpit: it adds comfort to brainfuck but no power; every new command can be written in brainfuck with a few spare cells.
Further
See also
Brainlove builds on Brainfuck.
Brainfuck derivatives
Cell-based
Write your own in Run Convert a program from Brainlove
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: brainlove.
Command line
shib run brainlove -e ',>,<$>>!<$<!>>$<!><<.>.' --input 'ab'shib manual brainloveSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/brainlove.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org