esolang

Direction

A 2D language where every arrow is gone once you have stepped on it.

2024 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 321

The idea

Direction is a grid language with a stack, like Befunge, and one catch. An arrow vanishes as soon as the pointer has used it, so a path can be walked only once. To build a loop, a program puts an S in front of each arrow it wants to keep. N does the opposite and makes the next command vanish after it runs.

The machine

CharDoes
< > ^ vPoint the pointer, then vanish
?Pop; go west on 0, east on more than 0
I ORead a number and push it; pop one and print it
DDuplicate the top
+ - * /Pop a, then b, and push b+a, b-a, b*a, b/a
1 0Push 1 or 0
S NThe next command stays for good, or vanishes after it runs
EStop

The pointer starts in the top-left corner going right. The specification says ? turns left on 0 and right above 0. Its three programs all meet ? going down and need 0 to go west, so ? sends the pointer west or east from any direction.

Example

The countdown pushes 3, then prints, subtracts 1 and loops back up through kept arrows.

The countdown pushes 3, then prints, subtracts 1 and loops back up through kept arrows. On 0 the ? sends it west onto a plain v, which takes it down to E.

The truth machine prints its input once. On 1 the ? sends it east into a loop of kept arrows that prints 1 forever. On 0 it goes west to E.

Expected: 0

The numeric cat reads and prints until a 0. Its first S keeps the v in the top-left corner, which every later pass needs, so a kept arrow has to stay kept.

Expected: 570

Patterns it teaches

Further

Two-dimensional languages

Stack-based

Write your own in Run Convert a program from Direction

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run direction -e 'IDOSvSOD<
    D   S
   E?S>S^' --input '0'
shib manual direction

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/direction.js

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

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