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
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
| Code | Does |
|---|---|
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 I | Read a character, a number |
o O | Print a character, a number |
c C | Write 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.
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.
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.
Patterns it teaches
- Code as data: output that is a program.
- Self-modifying code: the program grows while it runs.
- Quine: the endless half of the truth machine copies itself forward.
Further
- esolangs.org/wiki/Brook
- Muriel, which also builds the program it runs next.
See also
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 brookSource
- 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