Trajedy
Befunge with the stack taken out. All that is left to remember with is where the pointer is.
Jafet, 2017 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Jafet made Trajedy in 2017, as an attempt to remove the memory stack from Befunge. The name is said like tragedy. The pointer is a point, not a cell. It flies in a straight line at any angle and acts each time it crosses into a new square. Mirrors reflect it like light. Every other character is a beacon that turns it towards the nearest square with the same character.
Read the story
There is no other memory, so a program has to keep its data in the pointer itself. The specification shows how beacons can halve or double the pointer's offset from a grid line, which gives a stack of bits, and it proves Trajedy Turing-complete by building Fractran out of mirrors.
The machine
| Char | Does |
|---|---|
| space | Nothing |
. | The next square prints its character |
, | The next square takes a character of input, or an end marker |
? | If the next square holds . , ? or the end marker, it turns the pointer to the nearest I O Q or $ |
/ \ | A two-sided mirror from corner to corner |
| anything else | A beacon; turn towards the nearest point of another square with that character |
The pointer starts at the top-left corner, heading for the bottom-right corner of the first square, and halts when it leaves the program. Through a corner it enters the square diagonally opposite. It may never run along an edge; a program that makes it do so is invalid. Each line keeps its line feed as a character and is padded with spaces after it, so a line feed can be printed and can act as a beacon. This implementation works in exact fractions.
Example
The first w aims the pointer at the other w, but on the way it enters H, which turns it towards the other…
The first w aims the pointer at the other w, but on the way it enters H, which turns it towards the other H, flat through the middle of the row. Each . prints the next square, the mirrors fold the path into the next row, and the last . prints the line feed at the end of the third line.
The truth machine reads one character into the square after ,. That character is now a beacon itself, and the 0 or the 1 elsewhere in the program decides where it pulls the pointer. On 1 it prints 1 for ever. The cat loops until ? finds the end marker and turns towards $.
Patterns it teaches
- Two-dimensional control flow: at any angle, with no cells to step through.
- Turing completeness: reached with no memory but a fraction.
Further
See also
Two-dimensional languages
Write your own in Run Convert a program from Trajedy
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: trajedy.
Command line
shib run trajedy -e 'wH.H.e.l.l\
/ w. .,.o./
\.o.r.l.d.!.
'shib manual trajedySource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/trajedy.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org