esolang

Klein

A 2D language that runs on a surface of your choosing: a torus, a Klein bottle, a projective plane.

Wheat Wizard, 2017 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 3 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: Hello, World!

The idea

Wheat Wizard made Klein in 2017. The program is a square, and the square is the fundamental polygon of a surface. Three digits on the command line say how its edges are glued: which edge the north edge meets, and whether each pair of edges is joined straight or with a twist. That gives twelve surfaces. A pointer that leaves one edge comes back through the edge it is glued to, maybe mirrored.

Read the story

Its instructions are the same as Lost's, without the safety.

The machine

The pointer starts at the top left moving east. A stack and a scope, both with endless zeros at the bottom.

CharDoes
> < v ^Arrows
\ / \|Mirrors
[ ]Doors: reflect an eastbound or a westbound pointer, and flip to the other door when crossed sideways
! ?Skip the next cell; pop and skip it if not 0
: $ ( )Dup, swap, top to the scope, back from the scope
0-9 "Push a digit, toggle string mode
+ * -Add, multiply, negate
@End, and print the stack

This implementation runs only topology 000, the torus, where each edge meets the opposite one.

Example

On the torus, going west off the first cell comes back on the last one, so the string is read from the…

On the torus, going west off the first cell comes back on the last one, so the string is read from the right and the program ends on the @ it skipped at first.

Expected: hello

Patterns it teaches

Further

Self-modifying

Two-dimensional languages

Write your own in Run Convert a program from Klein

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: klein.

Command line

shib run klein -e '98*@'
shib manual klein

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/klein.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org