A Slow Language
A turtle walks the grid and works a stack, and being a turtle, it takes its time.
Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
A Slow Language is a fungeoid made for one of Truttle1's esolang jams. A turtle walks an infinite grid from the top left corner, one cell at a time, and every character it steps on is an instruction. Since turtles are slow, the interpreter waits 1 to 3 seconds, at random, before each move. This implementation leaves the wait out.
Read the story
Every value an instruction uses is popped. A . turns that off, so + leaves both numbers and puts the sum on top. Values can also go in registers. :a moves the top into register a when it is empty, and when it is full pushes it back and empties it.
The machine
| Character | Does |
|---|---|
r l u d | Turn right, left, up or down |
= | Go right if the top two values are equal, else left |
| | Go up if the top two values are equal, else down |
_ | Go right if the stack has a value, else left |
! | The same up and down |
? | Go a random way |
" | Toggle pushing mode, where each character pushes its code |
0 to 9, A to F | Push a number from 0 to 15 |
v ^ ~ | Pop, duplicate, reverse the stack |
+ - * / % | Arithmetic on the top two, the lower one first |
O o | Print the top as a character, as a number |
I i | Read a line as characters, read a number |
. | Toggle popping mode |
: | Use the register named by the next character |
x | End |
The specification does not say which way ! goes. This implementation sends it up when the stack has a value, as | goes up when two values match.
Example
The Hello World pushes the text in pushing mode and reverses the stack, so H is on top.
The Hello World pushes the text in pushing mode and reverses the stack, so H is on top. Then the turtle goes round a loop of six cells, printing a letter each time, until _ finds the stack empty and sends it left to x.
The second Hello World builds every letter from hex digits, 72 as 89*. It has no x, so after printing the ! the turtle walks on into the empty grid forever. This implementation stops the run there, without halting.
The truth machine reads a number and compares it with 1. On 0 the turtle goes left, pushes 0, prints it and ends. On 1 it goes right into a loop that prints 1 forever.
The cat reads a line, reverses it and prints it with the Hello World's loop.
Patterns it teaches
- Two-dimensional control flow: the turtle's path is the program.
- Stack machines: one stack, with popping that can be turned off.
- Nondeterminism:
?picks a way at random. In this implementation it comes from a fixed sequence, so a run replays.
See also
Two-dimensional languages
Stack-based
Write your own in Run Convert a program from A Slow Language
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: a-slow-language.
Command line
shib run a-slow-language -e 'rI~d l
x_Ou' --input 'cat'shib manual a-slow-languageSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/a-slow-language.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org