Rain
The pointer only falls or climbs. To move sideways it has to make a call.
dok, 2017 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
dok made Rain in 2017, after Befunge and ><>, to be hard to write but still possible to compile. The pointer starts in the top-left corner moving down, and it only ever moves up or down. > and < are calls. They look along the row for the first |, turn the pointer round and go on in that column, and ; returns to the cell after the call. So every column works as a function, and every call gets one local variable of its own.
Read the story
A space is an error, so a program is drawn as columns with gaps between them, and half of its code is read upwards.
The machine
| Char | Does |
|---|---|
0 to 9 | Push a digit |
+ - * / % | Arithmetic on the top two values; / rounds down |
( ) = | Push 1 or 0 for less than, greater than, equal |
^ \ _ ~ ` | Duplicate, swap, over, push the stack's length, drop | |
> < | Call the column at the first \| to the right or left |
; | Return to the cell after the call; on the main program, stop |
! ? | Skip the next cell; pop and skip it unless the value is 0 |
. , | Store and fetch the call's local variable |
# $ | Print a number or a character |
& @ | Read a line as a number, or one character |
" ' | Start and end a string, which pushes its character codes |
: \| | Do nothing |
] [ | Mark a tunnel that a call's search passes over |
Example
The call at the bottom runs the second column upwards.
The call at the bottom runs the second column upwards. The string pushes i before H, so the first $ prints H.
The factorial reads a number and calls itself through the third column, which multiplies on the way back.
The cat reads with @ and turns at each end of its loop with a call. @ reads a line at a time and gives its line feed back, so the output ends with one.
The specification also has a Fibonacci and Pascal's triangle, which also work. Its Hello world prints the 0 it pushed first as a character after the line feed. Its Ackermann function has its last ; one column too far right; moved back, it gives 9 for 2 and 3.
Patterns it teaches
- Two-dimensional control flow: columns as functions, rows only for calls.
- Stack machines: one stack, and one local variable per call.
Further
See also
Two-dimensional languages
Write your own in Run Convert a program from Rain
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: rain.
Command line
shib run rain -e ': ;
| <
@ $
^ ;
0 ?
) )
? 0
; ^
$ @
> |
;' --input 'cat'shib manual rainSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/rain.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org