Quiney

From Esolang
Jump to navigation Jump to search

Quiney is a tape programming language, like BF (Both in commands and style), whose variable system and commands are stored on the same, one-dimensional, infinitely long (in one direction) array, which can store the numbers 0 through 9. There are two independent cursors on the tape - one for execution, and one for reading/editing data. Its name refers to the ease with which quines may be written in the language. These numbers, for human readability, are actually commands that are commonly written as their representative characters. The commands in Quiney are as follows:

0 " " Null character. May also be represented as "_" for convenience. Doesn't perform a function, but it is used as a marker, as it allows escape from bracket pairs.
1 "[" The exact same as in the BF language.
2 "+" Rotates the selected value up one unit. (Roll over after 9).
3 "." Outputs the data selected by the cursor.
4 "}" Moves the data editor cursor forward one cell.
5 "{" Moves the data editor cursor back one cell.
6 "," Take an input (0 to 9, or one of the defined command characters) to the selected cell.
7 "-" Rotates the selected value down one unit. (Roll over after 0).
8 "]" The exact same as in the BF Language.
9 "*" Invert the character. Ex. 0 to 9, "[" to "]", "." to ",", etc.

The selected cell in the initiation of any program is the first. This allows for the one command, one character quine, "." If a command moves the data cursor past the last command, or the execution cursor moves past the last command of the program, a new command (set to " " by default) is added to the array. As such, all programs in Quiney run unendingly, either due to an infinite loop in the program, or by executing the infinite " " that follow the end of a program. The exception to this is bracket mismatch (see below).

Interpretation

Besides the above definitions, programs may throw run-time errors due to bracket mismatch: when attempting to pass over a bracket pair without a "]" or attempting to return to the beginning of a bracket pair without a "[". No program need pass a pre-check, as it may modify or never execute a seemingly errant bracket. For example, the below program should run because the end bracket is never read.

"[}]+[}+]]"

Programs may create unpaired, unread, unexecuted brackets, which is also OK. If the data cursor is on a value " " and the execution cursor reaches an unmatched "]", it can be safely ignored without error. The same is true of "[" which are reached when the data cursor is selecting a non-zero value. Such unmatched brackets may cause a bracket mismatch error or unintended result when attempting to resolve legitimate bracket pairs, though. The below programs run (infinitely) without error.

"["
" ]"

The above examples also illustrate the infinite nature of programs in Quiney: nothing inherently ends program execution. An interpreter may end a program after a maximum number of commands have been run, if a recognizably infinite state has been reached, or when a bracket mismatch has occurred. Programs may take advantage of this by inducing a bracket mismatch error to terminate execution.

Cellular Automaton

Quiney could be used as cellular automaton, mainly because it can systematically edit itself (by it's own rules).

Examples

Code is surrounded in quotes, to preserve the visibility of the space character.

Quines

The One Command Quine

"."

Quine-Six Char.

".[}.] "

Eight Char.

".}[.}]. "

Eight Char. Quine With Two Null

" .+[}.] "

Six Char.

"[.}]. "

Seven Char Quine

".[}.]} "

An n + 7 Quine

".[}.]}" (Repeating "}" or "{" can be inserted here) " "

Self Modifying

These programs self modify, morph, or destruct

Self Destruct (one Char)

"*"

Self Mutating program

"[ }]}[}]+[{]+[}[-]+] "

Which gets stuck in an infinite loop state, oscillating between the two states below:

"[[[[[[[[[[[[[[[[-]+]]"
"[[[[[[[[[[[[[[[ -]+]]"

Oscillators

only the first phase can be executed, the rest are visuals of the code state, their pointers aren't at cell 1.

Small Oscillator, 2 phase

"[[[-]+]]"
-other phases
" [[-]+]]"

Midsize Oscillator 4 phase

"[ }}[}]++ [-][{]]"
-other phases
"[ }}[}]++[[-][{]]"
"[ }}[}]+++[-][{]]"
"[ }}[}]++.[-][{]]"

Interpreters

You Decide (Simple, almost useless interpreter) The smallest interpreter, possibly ever. Fragile.

"[}]}[ ,]"
This has two useable, reasonable commands, "-", possibly a wait, turns into a ","
and a "," which asks for another input.
A space would knock the program into infinite loop,
and the "*" would do the same after the equivalence of one wait.
A close bracket would also loop infinitely after a period of one wait.
An open bracket would cause an almost instant error.
"." would cause an infinite output of itself, which could be considered a quine,
and a "+" would turn into a "." and continue outputting "."s
"{" would move the cursor to a null, causing the loop to stop and the program to end.
"}" would eventually move the cursor to a null character and end the program.

More Complex Interpreter Has different "Phases", initial program is Phase 1, other phases can be entered with certain commands.

"[}]{[}, {]"
-
---Phase 1---
Program will continue to take input after each command unless otherwise noted.
Null does nothing. "[" Creates error.
"," Asks for another input, but does nothing, possibly a "Skip next command".
"-" turns itself into a "," but doesn't ask for input, does nothing.
A "." prints a "." to the output.
A "+" turns into a ".", but does nothing.
A "]" Moves program to phase 2.
When a "*" is entered, it uses up one rotation.
"{" delays the interpreter one rotation.
"}" puts the interpreter into phase 3.
-
---Phase 2---
Almost a perfect self interpreter program (For Quiney)! Once the "]" has
been entered to get to this phase, one can enter a Quiney program with only a
few specific rules. As long as there are no spaces in the Quiney program being
inputted, one can simply type it in, and end it with a null character. For example:
"][.}]. "
can be typed in from the beginning of this interpreter to execute the Quiney program: 
"[.}]. "
-
---Phase 3---
A "{" Will put the interpreter into stage 4.
A "}" will end the interpreter.
A "[" will cause an error.
When a "]" is entered, interpreter enters phase 5.
-
---Phase 4---
A "]" must first be entered, else the program will crash. After the program receives this,
it enters phase 2. Although the actual code being executed is different, the interpreter
after the close bracket in Phase 4 and in Phase 2 are essentially the same.
-
---Phase 5---

This description is a WIP.

Computational class

Quiney is Turing complete, as brainfuck with decimal digit cells can be reduced to it.

Brainfuck Quiney Remarks
Beginning of program " * [ * } } * ] * } }" Moves cursor to end of brainfuck program representation. To support this, the

program representation is filled with alternating spaces.

End of program " } [ } } } ] - - } - - } [ [** " Moves cursor past end of used tape, adds "]]", then jumps across it. The "** " are the pre-initialized first brainfuck tape cell.
> " } [ * } * { ] * } * }" Each brainfuck tape cell takes 3 Quiney cells: First a "*" mark to allow the end of program code to seek to the end; then a reversed data cell to ensure the brainfuck tape area has no unbalanced Quiney loops; then a cell containing the actual data.
< " { { {"
+ " + { - }"
- " - { + }"
. " ." These work pretty much as in brainfuck, except for the

alternating spaces.

, " ,"
[ " ["
] " ]"