esolang

Quiney

A brainfuck whose tape is its own source code, so printing the tape prints the program.

2014 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 8 known programs · Test method

Run it

Expected: .[}.]

The idea

Quiney keeps the program and the data on one tape. Each cell holds a number from 0 to 9, and each number is also a command, written as its character. Two cursors move along the tape. One runs the commands, and the other reads and changes cells. Since the data cursor starts on the first command, . alone prints itself, and that is a one-character quine.

Read the story

Loops work as in brainfuck, but a program can rewrite its own brackets while they run. The specification shows programs that mutate, oscillate between states and destroy themselves. One of them reads a character into the very cell it is about to run, which makes a tiny interpreter.

The machine

ValueCharacterDoes
0space or _Nothing; a blank
1[Jump past the matching ] if the data cell is blank
2+Turn the data cell up, 9 back to 0
3.Print the data cell's character
4}Move the data cursor forward
5{Move the data cursor back
6,Read a character into the data cell
7-Turn the data cell down, 0 back to 9
8]Jump back to the matching [ unless the data cell is blank
9*Invert the cell, so v becomes 9 - v and [ becomes ]

Past the end the tape is blank, so a program never really stops; it runs on through blanks forever, unless a jump finds no partner, which is an error. As the specification allows, a run stops once only blanks lie ahead.

Example

The six-character quine.

The six-character quine. The loop prints the cells from the second on, and stops once it has printed the blank at the end.

The quine with two blanks. It prints the first blank, then turns it into a [ that is never printed again.

Expected: .+[}.]

Code is data. + turns the first cell, a ., into a }, so the second . prints something else.

Expected: .}

Patterns it teaches

Further

Self-modifying

Cell-based

Write your own in Run Convert a program from Quiney

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: quiney.

Command line

shib run quiney -e '.'
shib manual quiney

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/quiney.js

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

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