Gray Snail

From Esolang
Jump to navigation Jump to search

Gray Snail is a Turing-complete esoteric programming language designed by Jack Eisenmann in (probably) 2009. It has four commands: INPUT, OUTPUT, POP, and GOTO.

Environment

In its original environment, Gray Snail operates on a web page with three boxes: the code entry box, the input box, and the output box. All of the Gray Snail code is written in the code entry box. INPUT takes strings from the input box, while OUTPUT prints strings in the output box. Buttons on the web page are used to compile and run the code and to indicate when someone has finished writing input.

Description

Gray Snail has four commands: INPUT, OUTPUT, POP, and GOTO. These commands are always the first words in a line of Gray Snail code to function. If they aren't, then they can be used as variables, just like most arbitrary strings of characters.

  • POP Var1 Var2 String stores the character S (the first character of String) in Var1, and stores the rest of the string in Var2.
  • GOTO Label String1 String2: If String1 is the same as String2, execution skips to Label.
  • INPUT Var halts the program, and stores an input string in Var.
  • OUTPUT String prints String.

Additionally, any strings which are not in the marked positions after the command will not generally affect how the string functions.

If multiple outputs are in the code, the contents of the output box will be blanked between output statements. For example, the following code will only appear to print seen, because after unseen is printed to the output box, it will be blanked and seen will replace it.

OUTPUT unseen
OUTPUT seen

If you want to see both outputs, you can insert an INPUT statement in between the OUTPUT statements, like the following code.

OUTPUT unseen
INPUT whatever
OUTPUT seen

In order to use the input string stored in a variable, it must be contained within brackets [like this]. For example, take the following code:

POP first rest hello
OUTPUT first
INPUT whatever
OUTPUT [first]

The first output statement will print first because it will read the input as a string. The second output statement will print h because it will read the string contained within the variable name.

By default, the value contained within all strings, including the empty string, is undefined.

In order to manipulate strings with spaces in them, the entire string needs to be surrounded by quotation marks "like this". For example, to output Hello World, you need to write something like OUTPUT "Hello World". If you write OUTPUT Hello World, it will only print Hello.

This also applies to manipulating variables. For example, the following code:

POP a "useful part" aHell"o w"orld!
OUTPUT "[useful part]"

outputs Hello World. If the last line is OUTPUT [useful part], the code will stop running and nothing will be put out.

As you may have noticed in the last example, characters within the quotation marks count as part of the string, but characters around the quotation marks which are separated from the rest of the words by a space or newline also count as part of the string. In fact, strings can consist of multiple parts with quotation marks. Even something like:

POP a "useful part" "a""H""e""l""l""o"" ""w""o""r""l""d""!"
OUTPUT "[useful part]"

will output Hello world!

Examples

Hello World

OUTPUT "Hello World!"

Cat

INPUT this
OUTPUT [this]

Reverse Cat

Also available on the website in the link.

OUTPUT "Enter a string to reverse."
INPUT "original string"
POP a "reversed string" a
"begin string reversal loop"
POP char "original string" "[original string]"
POP a "reversed string" a"[char][reversed string]"
GOTO "exit string reversal loop" "" "[original string]"
GOTO "begin string reversal loop" a a
"exit string reversal loop"
OUTPUT "[reversed string]"

Implementations

Gray Snail's oldest implementation is on a website in Javascript.

External resources