Surface
The program and its memory are both drawn on a Klein bottle, and every arrow moves both pointers at once.
Madk, 2011 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Madk designed Surface in 2011. The code is a 32 by 16 field and so is the memory, and both are wrapped round a Klein bottle (the author meant a sphere). Going off the left or right edge comes back on the other side, as on a torus. Going off the top or bottom does not. The pointer stays on that row, slides half the width along, turns round, and from then on sees left and right, up and down and its turns the other way round, until the next crossing.
Read the story
There is one more twist. The arrows < > ^ v steer the instruction pointer and move the memory pointer in the same breath, so a program cannot choose where to go without also choosing where to look. Loops are marks. ( remembers a place and ] jumps back there while the cell is above 0.
The machine
| Command | Does |
|---|---|
> < ^ v | Move the memory pointer that way and send the IP that way |
+ - | Add one, take one away |
o e | Turn the IP clockwise, counter-clockwise |
c z | Turn, then become each other |
/ \ | Reflect, then become each other |
? ! | Skip the next cell if the cell is below 1, or above 0 |
* | Skip as many cells as the cell holds |
( ) ] x | Mark this place; go back to the mark; go back while the cell is above 0; drop the mark |
. : , | Print a character, print a number, read a number |
@ | Stop |
Text outside the 32 by 16 field is a comment.
Example
Thirty pluses along the top row, o turns the IP south, three more pluses and .
Thirty pluses along the top row, o turns the IP south, three more pluses and . prints 33, !.
TIO's Hello World. In the lower left the IP runs down a column of pluses, off the bottom edge, and comes up column 20, flipped, to print the comma. Flipped, its e turns it east instead of west, and the row of minuses brings the cell down to 32 for the space.
Further
- esolangs.org/wiki/Surface
- TIO's interpreter: github.com/TryItOnline/surface
See also
Two-dimensional languages
Cell-based
Write your own in Run Convert a program from Surface
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: surface.
Command line
shib run surface -e '++++++++++++++++++++++++++++++o
+
+
+
.
@'shib manual surfaceSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/surface.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org