Detour

From Esolang
Jump to navigation Jump to search

Detour is a cell-based esolang where memory can only be edited indirectly.

Description

In Detour, memory is stored on a tape of cells that extends infinitely in both directions. Each cell is associated with an integer representing its position, and stores an integer value and a pointer to another cell. Before any code is executed, each cell stores the integer corresponding to its position and points to itself.

While the pointers can be moved around freely, there is no way to do anything with the value stored in a cell beyond copying it to another cell, checking if it's equal to the value stored in another cell, or outputting it; in Detour, all numbers are interchangeable beyond their starting position. This also means that if you overwrite a number, there's no way to get it back: for example, if your code starts with v3 (which copies input into cell 3), it won't be able to output the number 3 unless the user happens to input a 3 at some point. Because of this, it's impossible to make a program to do anything that can result in any integer (e.g. adding two numbers) without representing some of them differently (e.g. representing negatives by outputting -1 and then the magnitude of the number separately).

Syntax

# # Make the cell at the position of the first number point at the cell at the position of the second number.
#+ Make the cell at position # point at the cell to the right of the one it was pointing at before.
#- Make the cell at position # point at the cell to the left of the one it was pointing at before.
#v Request user input, and overwrite the cell that cell # is pointing at with it.
v# Request user input, and overwrite cell # with it.
#^ Output the value stored at the cell that cell # is pointing at.
^# Output the value stored at cell #.
#> Copy the value stored at cell # to the cell it's pointing at.
#< Copy the value stored at the cell that cell # is pointing at to cell #.
#? Perform indented code below this line if cell # and the cell it's pointing at store the same value.
#: Repeat indented code below this line until cell # and the cell it's pointing at store the same value.

Example Code

Cat

0v
0^

Hello World!

Note that this prints the ASCII value of each character, since Detour can't print characters.

^72
^101
^108
^108
^111
^32
^87
^111
^114
^108
^100
^33

Add two non-negative integers

v-1
v-2
-1 0
-1:
  -1+
-2 0
-2:
  -1+
  -2+
-1^

Print powers of two forever

-1 1
-3 -4
-3:
  -1^
  -1<
  -2 -1
  -2<
  -2 0
  -2:
    -1+
    -2+

Implementations

Python