esolang

Brook

A queue language with a third output. What goes there is not shown; it is run.

Nathan van Doorn, 2011 · Turing complete: unknown · ●●● hard · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: Hi

The idea

Nathan van Doorn made Brook in 2011. Next to printing characters and numbers, a Brook program can write characters and numbers into its subcontinuity, a second Brook program with its own queue. That program runs as soon as its next command can be read without doubt, while its parent is still writing it. It can write a subcontinuity of its own, so a finite program can start an endless one.

The machine

CodeDoes
n^Push n onto the queue; a lone ^ pushes 0
n(...)Repeat the body n times; a lone (...) is a comment
v U @Drop, double, move the front to the back
+ -Sum and absolute difference of the front two
i IRead a character, a number
o OPrint a character, a number
c CWrite a character, a number into the subcontinuity

Popping an empty queue gives 0. Digits count only right before ^ or (, so 54x^ pushes 0. Numbers print as bare digits with nothing between them.

Example

The second program writes 7^O into its subcontinuity.
Expected: 7!

The second program writes 7^O into its subcontinuity. That runs, and prints 7, before the parent reaches its own 33^o.

The Fibonacci program prints 1 and 1 itself, then writes 1^1^8(U+@U@O) for the rest.

Expected: 11235813213455

The truth machine never prints itself. On 0 it writes 1(0^O)0(...), which prints 0. On 1 it writes a program that prints 1 and writes a copy of itself, again and again.

Expected: 0

Patterns it teaches

Further

Queue-based

Write your own in Run Convert a program from Brook

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: brook.

Command line

shib run brook -e 'I2(1^@O)2^-2(1^@C94^@c)C40^c85^c43^c64^c85^c64^c79^c41^c' --input '10'
shib manual brook

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/brook.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org