Erase

From Esolang
Jump to navigation Jump to search

Erase is an esolang where you may erase and insert characters directly into the program code.

Commands

The instruction set encompasses five operations:

Command Description
erase <x> Erases the character at the position <x>.
write <a> <x> Writes the literal character <a> to the position <x>.
print <x> Prints the character at the position <x>.
if <x> <y> <z> Goes to the position <z> if the character at the position <x> equals the literal character <y>.
goto <x> Goes to the position <x>.

Literal Characters

Literal characters, if required as arguments, must be stated directly and without further demarcations. The admissible content includes, of course, whitespaces, such as newlines.

Positions

Positions may be zero-based character indices into the program, or line numbers, likewise commencing with the index 0.

A character index constitutes an unsigned decimal integer number, while a line number is signified by a prefix of $, succeeded by such an unsigned subscript.

Examples

hello world

This program displays the message “hello world”:

helo wrd
print 0
print 1
print 2
print 2
print 3
print 4
print 5
print 3
print 6
print 2
print 7

Truth machine

A truth-machine is simulated in the code below. By default, a zero (0) input is configured. In order to impose an input of one (1), please substitute the 0 character in the first line by 1.

input: 0
print 7
if 7 1 9

100 10 1 program

100
print 0
print 1
print 2
print 3
if 2 0 $9
if 1 0 $11
if 0 0 $13
goto $15
erase 2
goto $1
erase 1
goto $1
erase 0
goto $1
end

Interpreter

  • Common Lisp implementation of the Erase programming language.