Self-modifying Brainfuck#
Brainfuck whose tape starts with its own source code, and whose data pointer starts on the first character of it.
None1, 2023 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
None1 made this variant of Self-modifying Brainfuck in 2023. In both, the program text is loaded onto the tape, so the program can read its own characters and change them. The only difference is where the data pointer starts. In Self-modifying Brainfuck it starts just after the code; it starts on the first character of the code, so nothing to the left of the program is ever needed.
Read the story
That makes text cheap. A program can begin with the text it wants to print and then walk over it.
The machine
The tape holds the program's characters, then a million zero cells. The code pointer and the data pointer both start at cell 0.
| Char | Does |
|---|---|
+ - | Add or subtract 1, wrapping at 256 |
> < | Move the data pointer; below cell 0 is an error |
, . | Read a byte (0 at the end) or print one |
[ ] | Brainfuck's loop, matched on the tape as it is now |
Any other character is skipped. The run stops when the code pointer passes the end of the original text.
Example
[.>] is a quine.
[.>] is a quine. The data pointer sits on [ itself, so the loop prints its own four characters and stops on the zero after them. Text put after it is printed too.
The Hello World needs its line feed. The loop subtracts 10 from each cell of the text, prints the cell with the 10 added back, and stops at the line feed, the one cell that becomes 0.
Ideas it shows
See also
Self-modifying Brainfuck# builds on Brainfuck.
Self-modifying
Brainfuck derivatives
Write your own in Run Convert a program from Self-modifying Brainfuck#
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: self-modifying-brainfuck-sharp.
Command line
shib run self-modifying-brainfuck-sharp -e '[.>]'shib manual self-modifying-brainfuck-sharpSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/self-modifying-brainfuck-sharp.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org