Circlefuck
Brainfuck on a ring of bytes that starts out as the program. Code and data share every cell.
Koen, 2012 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Koen designed Circlefuck in 2012 as a brainfuck with a von Neumann architecture. The tape is a ring exactly as long as the program, and each cell starts out holding one character of the source. The data pointer and the instruction pointer both start on the first cell. So a program can print and rewrite its own instructions, and a letter in the source is data that the instruction pointer walks over.
Read the story
The ring has no end to run off. A program halts only at @.
The machine
| Char | Does |
|---|---|
> < | Move the data pointer one cell round the ring |
+ - | Add or subtract 1, modulo 256 |
. , | Print the cell; read a byte into it, or nothing at the end of input |
[ ] | Jump to the matching ] if the cell is 0; back to the matching [ if not |
@ | Halt |
# | Skip the next cell |
{ | Insert a 0 cell before the data cell and move onto it |
} | Delete the data cell |
Every other cell does nothing. The characters 33 to 126 are one cell each. Escapes such as \0, \n and \x41 give the other bytes, and spaces and line breaks only separate. A bracket's match is looked for on the ring as it is at that moment.
Example
The first Hello World keeps its text at the start.
The first Hello World keeps its text at the start. None of the letters is an instruction, so the instruction pointer walks through them, and then the loop prints them. A comma would read input, so this one has none.
With the text to the left of the code, the instruction pointer halts before it ever reaches the comma.
The quine is seven characters. The { puts a 0 cell just before the first one, and the loop prints the ring until it comes round to that 0.
The specification says its examples were written before there was an interpreter. Its longer quine and its narcissist overwrite their own brackets and do not run as written. The specification also turns any brainfuck program into Circlefuck, with a flag cell beside each data cell, and that construction works.
Patterns it teaches
- Self-modifying code: the third Hello World adds 2 to a
*and turns it into a,once the instruction pointer has passed it. - Code as data: the program is the initial memory.
- Quine: printing the tape prints the program.
- Turing tarpit: brainfuck on a finite ring, made unbounded with
{.
Further
See also
Circlefuck builds on Brainfuck.
Self-modifying
Brainfuck derivatives
Write your own in Run Convert a program from Circlefuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: circlefuck.
Command line
shib run circlefuck -e '{>[.>]@'shib manual circlefuckSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/circlefuck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org