Dig
A mole crawls over a grid. Above ground it can only turn; to do any work it has to dig.
Emerald, 2020 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 10 known programs · Test method
Run it
The idea
Emerald made Dig in 2020, after Befunge and ><>. The grid has a third direction, down into the ground. Arrows and turns work only on the surface. Letters, output, input and arithmetic work only underground, and the mole gets there with $, which digs through as many cells as the digit next to it says.
Read the story
So a program is drawn in two layers. The top row holds the path, and the digits beside it say how far each dig goes.
The machine
Above ground.
| Char | Does |
|---|---|
^ > ' < | Point the mole up, right, down or left |
# | Turn left if the value beside is 0, right if 1 |
$ | Dig through the next n cells, n being the digit beside |
@ | Halt |
Underground.
| Char | Does |
|---|---|
letters, digits, .,!? | The mole's value becomes this |
% | A space if the digit beside is 0, a line feed if 1 |
= ~ | Read a character or a number |
: | Print the value, then set it to 0 |
+ - * / | Change the value by the digit beside |
; | Keep the mole's value in this cell |
"Beside" means a neighbour, tried up, right, down, left. The mole starts in the top-left corner.
Example
Hello World.
Hello World. Each $ has an 8 under it and digs through eight cells. The 0 under % makes a space.
The NAND gate reads two bits. The first # turns on the first input, kept in the ; beside it.
The truth machine. On 0 it turns up, digs one cell through : and halts. On 1 it turns down into a loop that adds 1 and prints it. The specification leaves open whether ; takes the value from the mole or copies it; it has to take it, or the loop would print 2, 3, 4.
Patterns it teaches
- Two-dimensional control flow: with a layer under the grid where the work happens.
Further
See also
Two-dimensional languages
Cell-based
Write your own in Run Convert a program from Dig
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: dig.
Command line
shib run dig -e ''\'' @
:
$1
>$~;#
2 >$+:'\''
^21 <' --input '0'shib manual digSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/dig.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org