Dip
Four commands on a stack of counters. The loop counts down, and ; sinks the top to the bottom.
D, 2023 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
D made Dip in 2023 as a Turing tarpit. It has no subtraction, no swap and no test, only a loop. The loop pops a number, and while that is not 0 it pushes one less and runs its body. So every loop counts its own counter down. Anything under the top is reached with ;, which sinks the top to the bottom of the stack.
Read the story
The specification proves Dip Turing complete by compiling The Waterfall Model into it, one waterclock at a time.
The machine
| Command | Does |
|---|---|
0 | Push 0 |
' | Add 1 to the top |
; | Pop the top and put it at the bottom |
( body ) | Pop N; while N is not 0, push N - 1, run the body and pop again |
The specification has no input or output. This implementation starts the stack with the numbers of the input, the first at the bottom, and the stack is printed at the end, bottom first, the way the specification writes it.
Example
Predecessor.
Predecessor. The program first sinks a 0 under the number. The loop pops 5, pushes 4 and sinks it under the 0. Then it pops the 0 and ends, which leaves 4.
Add counts the top number down and adds 1 to the number under it each time. Multiply keeps a total and a copy of the first number, and adds the copy to the total once for each count of the second. An empty loop () counts the top down to 0 and drops it, so ()() at the end drops the two helpers.
The Waterfall Model program starts by pushing its three waterclocks, C, B and A.
Patterns it teaches
- Turing tarpit: four commands, and the proof goes through a waterclock model.
- Counter machines: every value is a counter that goes up by one and comes down only in a loop.
- Stack machines: a stack that is turned round from the top to the bottom.
Further
See also
Stack-based
Write your own in Run Convert a program from Dip
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: dip.
Command line
shib run dip -e '0;(;)' --input '5'shib manual dipSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/dip.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org