Wheat

From Esolang
Jump to navigation Jump to search

Wheat is an esolanguage designed by Keymaker in 2009. The language is based on outputting and inputting, only what has been output on a previous cycle can be input on the current one. The buffers last only one cycle; if the data of previous cycle is not read on current cycle, on the next cycle it can not be accessed, it will all be erased, replaced by the output of the current cycle (if any, otherwise the empty string is used). Reading empty buffer returns the empty character/string. (The language can not read external input, and is thus classified output-only.) There are no limits for the program sizes or the output it creates. The program runs endlessly unless terminated with the terminating instruction. By cycle it is meant the lines of the program, from top to bottom, executed once. There are 36 one-character registers, each set to empty string on every cycle. Their content may be modified only by inputting into them.

Computational class

Wheat is Turing-complete. This is proven with a Cyclic Tag interpreter written in Wheat.

Instructions

Instruction Purpose
output outputting strings or the contents of registers
input reading input into registers
if conditions, for comparing a register to a character (excluding the empty character/string)
for-input looping (always finite)
terminate terminating the program

There are also comment lines, indicated by a '-' character in the very beginning of the line, no matter how the surrounding lines are indented. See the official specs for better explanations.

Example program

This program outputs the Thue-Morse sequence along with a new-line before every number:

input a
if not a N:
 output N
 output "0"
if a N:
 output N
 for-input b:
  if b "0":
   output "01"
  if b "1":
   output "10"

First, input is read into the a register. On the very first cycle there is no input, and the zero string is stored in the a (which already had it, the registers being cleared in the beginning of every cycle). Then, it is checked if the a register is not N, the new-line character, and on the very first cycle, the a indeed is not that. Thus, the indented content is executed; a new-line is printed and the first number, 0, is output. On the first cycle nothing else is executed, a not being N, and as the program pointer goes past the last line a new cycle begins. On the second cycle, what was output on previous cycle ("\n0") is there to be read as input. The register a receives a new-line as its value. 'if not a N:' is not true anymore, the a having a new-line as its value. The next, 'if a N' is true this time (and forevermore in this program, as every cycle will have a new-line as the first character of the input-to-read), and a for-input loop is executed: input is read, as long as there is some, into the b register. The value of b is inspected, if it is '0', "01" is printed, if it is '1', "10" is printed. Thus, the output created by the second cycle is "\n01". The third cycle creates "\n0110", the fourth "\n01101001", and so forth. This example conveniently works without creating any trash output, but larger and more complex programs tend to do so.

Interpreter

From 2009 till 2012, the language's only interpreter was an extremely buggy Perl program that required comment lines placed in the Wheat programs to affect its own bugs somehow and make it work right. Interesting as this behaviour might be, the old interpreter has now been removed and there is a new one written in Python, one that should work perfectly and even recognize programs that are not valid. Here: wheat.py

External resources

  • Wheat page (the specs, programs (including a quine), an interpreter)