esolang

Brainfuck But With Buffer

Brainfuck with a middleman. Nothing reaches the tape without passing through the buffer.

Turing complete: yes · ●○○ easy · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: H

The idea

BBWB is brainfuck with one buffer between you and the tape. + and - change only the buffer. To change a cell you load it into the buffer with v, work on the buffer and write it back with ^. Brainfuck's + becomes v+^, and the specification gives a table that turns every brainfuck command into BBWB this way. The buffer also prints and reads in two ways, as a character or as a decimal number.

Read the story

The tape is a ring with a fixed number of cells, so the pointer wraps round at both ends.

The machine

CharDoes
+ -Add or take 1 from the buffer, wrapping between 0 and 255
#Set the buffer to 0
^ vWrite the buffer into the cell; load the cell into the buffer
< >Move to the previous or next cell
. :Print the buffer as a number; print it as a character
, ;Read a number into the buffer; read a character into it
[ ]Loop while the current cell is not 0
@Print the tape for debugging; here it does nothing

The specification gives each command as a line of C. It does not say how many cells the ring has, so this implementation gives it 30,000. Every other character is a comment.

Example

The first line of Hello, world! Nine goes into the cell, and the loop adds 8 to the next cell nine times.

The first line of Hello, world! Nine goes into the cell, and the loop adds 8 to the next cell nine times. Each of those additions loads the cell with v and writes it back with ^.

The truth machine reads a number, stores it and prints it, then prints it again for as long as the cell is not 0. On 1 it never stops.

Expected: 0

The whole Hello, world! from the specification. Each line builds one letter on a fresh cell. The O is 80 less one and the W 88 less one, and the letters come out in capitals.

Expected: HELLO, WORLD!

Patterns it teaches

  • Turing tarpit: brainfuck, with one more step between the program and the tape.

Further

Brainfuck But With Buffer builds on Brainfuck.

Brainfuck derivatives

Cell-based

Write your own in Run Convert a program from Brainfuck But With Buffer

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: brainfuck-but-with-buffer.

Command line

shib run brainfuck-but-with-buffer -e ',^.[.]' --input '0'
shib manual brainfuck-but-with-buffer

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/brainfuck-but-with-buffer.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org