Brain-flak

Code:

Input:

Options...

Input Type...


Output Type...


Output:



What is this?

Brain-Flak is a "Turing-tarpit", e.g. a language which can, in theory compute anything, but in reality is very inconvenient and painful to use. It was somewhat inspired by Brainfuck, the original turing-tarpit, but it was designed with the goal of being comprised entirely of nested and balanced brackets.

Tutorial

Brain-Flak has two stacks. One stack is the "active" stack, and the other is the "inactive" stack. If an empty stack is popped, it will return 0. That's it. No other variables. When the program starts, each command line argument is pushed on to the active stack.

The only valid characters in a Brain-Flak program are '()[]{}<>', and they must always be balanced. There are two types of functions: Nilads and Monads. A nilad is a function that takes 0 arguments, and a monad is a function that takes 1 argument. Here are all of the nilads:

These values of these commands are summed together when they are evaluated. So if we had a '3' on top of the active stack, this snippet:

()(){}
        

would evaluate to 1 + 1 + active.pop() which would evaluate to 5.

The monads take one argument, a chunk of Brain-Flak code. Here are all of the monads:

The (...) monad will also evaluate to its argument, so

(()()())
        

Will push 3 but

((()()()))
        

Will push 3 twice.

The {...} monad will evaluate to the sum of all runs. So if we had '3' and '4' on the top of the stack:

{{}}
        

would evaluate as 7.

When the program is done executing, each value left on the active stack is printed, with a newline between. Values on the other stack are ignored.

Congratulation! You have learned how to write brain-flak code.

Tools

Here are some tools that can be useful for writing brain-flak.