Brook

From Esolang
Jump to: navigation, search

Brook is a language created by Nathan van Doorn in 2011 with the gimmick that the program can produce and immediately execute a potentially infinite length program written in Brook. It is unknown if it is Turing-complete or not.

Structure

A Brook program is made up of a sequence of characters, parsed as numbers when appropriate. If a number is not postfixed with ^ or a (...) contstruct, it is ignored. ^s and (...)s not prefixed with numbers are assumed to have an invisible zero before them, which makes comments possible with (...)s. All invalid characters are ignored, however this happens after the previous step, so 54¬^ is equivalent to 0^.

Data is stored in one ways: a queue, which is unique to each "continuity", or stream of code. Popping from an empty queue returns a zero.

Input and output are similar to Piet, in that they both exist for characters and numbers. However, Brook also has an extra output, which is not displayed, but instead executed, as soon as there is enough to execute unambiguously.

Commands

n^      pushes n to the queue
v       pops a number from the queue and discards it
U       pops a number from the queue and pushes it twice
@       pops a number from the queue and pushes it once
+       pops two numbers from the queue and pushes their sum
-       pops two numbers from the queue and pushes their absolute difference
i       pushes the ASCII (or Unicode, or whatever) value of the next character from input into the queue
o       pops a number from the queue and prints the character with it as its character code
c       pops a number from the queue and adds the character with it as its character code to the current continuity's subcontinuity
I, O, and C work like their lower case equivalent but use numbers rather than characters

In addition to these there is also the n(...) construct, which repeats ... n times. This, in almost any other language, would be rather redundant, although possibly nice for sufficiently large values of n, but in Brook is quite useful.

Examples

I2(1^@O)2^-2(94^@c1^@C)C40^c85^c43^c64^c85^c64^c79^c41^c

Calculates the first n Fibonacci numbers where n ≥ 2 (if n < 2, weird stuff happens)

See also