MailBox
A program is a set of e-mail filters. Nothing happens until a message arrives.
2009 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
MailBox, from 2009, is built from numbered mailboxes. Each box has filter rules, and each rule has actions that run when it is true. A message is a subject line. When one reaches a box, the box counts it and tries its rules in order. The actions send new messages, forward the one that came in, delete messages or print.
Read the story
The only memory is how many messages each box holds. That is enough. The specification turns any counter machine into MailBox, with one box per register, so MailBox is Turing complete.
The machine
| Rule | True when |
|---|---|
contains "s" | The subject contains s |
contains count | The subject contains this box's count, written in digits |
from N forwarded | The message came from box N, or was forwarded |
empty once | The box is empty; the rule was never true before |
and or not ( ) | Combine rules |
| Action | Does |
|---|---|
send "s" to N | Sends a message; send count "s" sends one per message in the box |
send input to N | Sends a line of input |
forward to N | Passes the message on |
delete empty | Removes one message, or all of them |
output | Prints the subject; output without "s" drops every s first |
output count N | Prints how many messages box N holds |
At the start every rule is tried once, in the order of the source. After that messages are handled in the order they were sent, and a rule is only tried when a message reaches its box.
Example
The program mails itself.
The program mails itself. The message starts with output, so the second rule prints it without that word.
Three messages to box 1 leave it holding three, and box 2 prints that number.
The Fibonacci program keeps the last two numbers as the counts of boxes 1 and 2 and prints 2, 3, 5, 8, 13 and on without end.
Patterns it teaches
- Counter machines: a box's count is a register.
- Turing completeness: the specification builds increment and jump if zero from filters.
Further
See also
Object-oriented paradigm
Write your own in Run Convert a program from MailBox
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: mailbox.
Command line
shib run mailbox -e 'box 0
(once)
send input to 1
box 1
(from 0)
output' --input 'hello'shib manual mailboxSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/mailbox.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org