Dig
| Paradigm(s) | Imperative paradigm |
|---|---|
| Designed by | User:Emerald |
| Appeared in | 2020 |
| Memory system | Cell-based |
| Dimensions | Two dimensional |
| Computational class | Unknown computational class |
| Major implementations | Python interpreter by User:Bangyen |
| Influenced by | Fish, Befunge |
| File extension(s) | .dig, .dg |
Dig is a language made by User:Emerald using a 2d grid, with a 3rd direction for the language’s namesake, Dig. It is inspired by Befunge-93 and ><>, but is no way related to DigFill, a similarly sounding language.
Commands
There are 2 types of commands in Dig, Movement and Work. The main difference is that Work only can be executed underground, accessible by the dig command; meanwhile, movement is restricted overground.
Movement
| Command | What it does |
|---|---|
| ^ | Points Mole up |
| > | Points Mole right |
| ' | Points Mole down |
| < | Points Mole left |
| # | Rotates Mole to left when value beside it is 0, and right when 1. When it’s neither of those, keep straight. |
| $ | Mole “digs” to the 3rd dimension, keeping its direction until it has moved the amount of tiles beside the $ |
| @ | Halt |
Underground
| Alpha-numericals and .,!? | When Mole passes over, memory is overwritten with value |
| % | Overrides current value with space when 0, and newline when 1 |
| = | Overrides current value with a single character from user |
| ~ | Overrides current value with a single integer from user |
| : | Outputs Value in memory then, replaces it with 0 |
| + | Overrides current value with itself plus the number besides the + |
| - | Overrides current value with itself minus the number besides the - |
| * | Overrides current value with itself times the number besides the * |
| / | Overrides current value with itself divided by the number besides the / |
| ; | When Mole passes over, the “;” is given the Moles current value |
Interpreters when faced with more than one value next to “#”, “$”, or “%” should prefer use up, right, down, left.
The mole is the pointer in the program, and starts from the top-left. It needs an arrow to guide its initial direction.
Memory storage
The Mole starts with a value of 0, but can be overwritten with 0-9 | a-Z
Programs
Hello World
>$H:e:l:l:$o:%:W:o:$r:l:d:!:@ 8 8 0 8
Cat (Never stops)
>$=:' ^2 <
Truth Machine
' @
:
$1
>$~;#
2 >$+:'
^21 <
NAND Gate
A NAND gate by User:Bangyen.
'2 > $~ >$ 1:@
>$~;#@2 3
> $~;#@2
> $0:@
Boolean Function Conversion
A Python program by User:Bangyen to implement a given boolean function in Dig.
from inspect import signature
def convert(func):
num = len(signature(func).parameters)
total = 2 ** (num + 1) - 1
lines = ['' for _ in range(total)]
pos = [total // 2]
for j in range(num + 1):
if j < num:
for k in range(total):
if k in pos:
lines[k] += '>2$~;#@'
else:
lines[k] += ' ' * 7
pos = [i + 2 ** (num - j - 1) for i in pos] + \
[i - 2 ** (num - j - 1) for i in pos]
for k in pos:
lines[k] = lines[k][:-2] + '> '
else:
for k in range(2 ** num):
arg_list = [0] * num + [int(i) for i in bin(k)[2:]]
lines[k * 2] += f'>$3{func(*arg_list[-num:])}:@'
lines[0] = '\'' + lines[0][1:]
return '\n'.join(k for k in lines).replace('> >', '> ')
For example, convert(xor) produces the code
' > $30:@
> 2$~;#@
> $31:@
>2$~;#@
> $31:@
> 2$~;#@
> $30:@