Denver-Augusta-Harrisburg
Every value is a thread, and the only thing a thread can send is another thread.
2022 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Denver-Augusta-Harrisburg is a language of threads that pass messages, from 2022. There are no numbers, no characters and no data of any kind. A variable holds a thread, a message is a thread, and when a message arrives the receiver also learns who sent it.
Read the story
Even input and output are threads. The program starts with one thread running main and a system thread that hands out the others. Send the system thread to itself and it answers with the input thread; send that and it answers with the output thread. Sending anything to the input thread gets the input thread back for a 1 bit and null for a 0 bit. Sending null to the output thread writes a 0, and anything else a 1.
The machine
| Statement | Does |
|---|---|
x < y | Assign |
x < [r a b] | Start a thread on routine r with arguments a and b |
{ ... } | Loop until a break |
break continue | Leave or restart the innermost loop, or the one with that label |
[ arm arm ... ] | Wait until one arm can meet another thread, run it, and go again |
to < msg { ... } | An arm that sends msg to the thread to |
msg who < a b { ... } | An arm that receives from a or b, or from anyone |
Any statement or arm can carry guards. a=b and a!b compare threads, =a asks that a has not exited and !a that it has. When no arm is active, or every arm waits on a thread that has exited, the statement is passed. A routine body is a loop too, and the run ends when main exits.
The specification leaves the order of threads open. This implementation takes turns in the order they were made, the first arm that can go is the one that goes, and bits are read and written high bit first.
The specification also lets a thread send a message to itself, but does not say which of its two arms then goes. This implementation leaves that out, so a thread never meets itself.
Example
The cat.
The cat. The first two statements fetch the input and output threads. The third is a little state machine with three arms. It asks the input thread for a bit, receives the answer in b, and passes b on to the output thread. When the input thread exits at the end of the input, the arm that waits on it can never go, so the statement is passed and break ends main.
The specification also has routines for a lock, a list cell, a stack and a tape, without a main to run them. The lock runs under a small main that acquires, queries and releases it.
Patterns it teaches
- Nondeterminism: which thread goes first, and which of several ready arms succeeds, is left to the implementation.
See also
Also in Strange time
Write your own in Run Convert a program from Denver-Augusta-Harrisburg
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: denver-augusta-harrisburg.
Command line
shib run denver-augusta-harrisburg -e 'main system {
[in=null system < system {[in _ < system {break}]}]
[out=null system < in {[out _ < system {break}]}]
[state=null in < self {state < in}
state=in b _ < in {state < out}
state=out out < b {state < null}
]
break
}' --input 'hi'shib manual denver-augusta-harrisburgSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/denver-augusta-harrisburg.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org