esolang

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

Expected: Hello, world!

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

RuleTrue when
contains "s"The subject contains s
contains countThe subject contains this box's count, written in digits
from N forwardedThe message came from box N, or was forwarded
empty onceThe box is empty; the rule was never true before
and or not ( )Combine rules
ActionDoes
send "s" to NSends a message; send count "s" sends one per message in the box
send input to NSends a line of input
forward to NPasses the message on
delete emptyRemoves one message, or all of them
outputPrints the subject; output without "s" drops every s first
output count NPrints 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.

Expected: hello

Three messages to box 1 leave it holding three, and box 2 prints that number.

Expected: 3

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

Further

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 mailbox

Source

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