Rail
The program counter is a train. It can only go where track has been laid, and it cannot turn sharper than 45 degrees.
Jonathon Duerig, 2005 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 6 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Jonathon Duerig invented Rail in 2005. In most two-dimensional languages the instruction pointer flies over the grid like a pinball. In Rail it is a train. It moves only along - | / \ rails, it keeps going straight where it can, and it bends at most 45 degrees from one cell to the next. Whitespace is not track, so a train that runs out of rail crashes.
Read the story
Duerig also avoided minimalism on purpose. Rail has functions, local variables, strings, LISP-style lists and lambdas. Text between brackets is read in the direction the train travels, so the same constant reads backwards when the train comes the other way.
The machine
A program is a list of functions. Each starts on a line beginning with $, with its name in single quotes, and the train starts on the $ going south-east. main runs first.
| Piece | Does |
|---|---|
- \| / \ | Rails |
* + x | Junctions: any direction, straight only, diagonal only |
< > ^ v | Pop t or f; true takes the arm to the train's right, false to its left |
@ # | Reverse the train; end the function |
[text] | Push a string; \n\ and \[\ are quoted palindromically |
(!x!) (x) | Pop into a variable; push it |
{f} {} | Call a function; call the lambda on the stack |
& | Push a lambda that runs on past the &, and reverse |
a s m d r | Add, subtract, multiply, divide, remainder |
g q t f | Greater, equal, true (1), false (0) |
c p z | Cut, append, size of a string |
n : ~ | Empty list, cons, break up |
o i e | Print, read a character, end of input? |
u ? b | Stack depth, type name, crash with a message |
Every command is also a junction that the train passes straight through.
Example
The second program pushes star, bounces off @ and reads the same constant backwards on its way west, so…
The second program pushes star, bounces off @ and reads the same constant backwards on its way west, so it prints rats and then star. The third is a cat. At < the train pops the end-of-input flag. On f it turns left into the loop that reads and prints a character, on t right to the #.
Further
See also
Functional paradigm
Two-dimensional languages
Write your own in Run Convert a program from Rail
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: rail.
Command line
shib run rail -e '$'\''main'\''
-[Hello, World!]o#'shib manual railSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/rail.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org