# Mini-Flak

**Mini-Flak** is a derivative/minimisation of Brain-Flak, created in Category:2016, most likely by User:Wheatwizard.

## Specification

Mini-Flak's main storage is a stack of unbounded integers (which can go negative). The stack is initially an infinite stack of the number 0.

Mini-Flak has two sorts of commands: nilads and monads. A program as a whole is just a list of commands, which are executed in sequence when the program is run.

Nilads are commands that take no arguments; when executed, they possibly change the stack, then return an integer. There are two nilads:

`()`

: Always returns 1.`{}`

: Pops the stack, and returns the popped value.

Monads are commands that refer to a nonempty list of other commands (sort-of like blocks in other languages). The monad is written as a pair of grouping characters with the other commands it refers to placed inside the monad (e.g. `(()())`

is a `(…)`

monad which refers to two `()`

nilads). The commands referred to by the monad are not automatically executed when the monad is (although most of the time, the monad will execute them as part of its effect). Just like nilads, monads will do something when executed (possibly changing the stack), then return an integer. There are three monads:

`(…)`

: Execute all the referred-to-commands, adding together their return values. Push the resulting sum of return values onto the stack, and return it (in addition to pushing it onto the stack).`[…]`

: Execute all the referred-to-commands, adding together their return values. Return minus the resulting sum of return values. (This command does not directly change the stack, although it may change it indirectly as a consequence of executing commands that change the stack.)`{…}`

: If the top element of the stack is 0, do nothing and return 0. Otherwise, execute all the referred-to commands, adding together their return values, then execute this`{…}`

command again, adding on its return value. Return the resulting sum of return values. (For example, if there are three 2s on top of the stack and the rest of the stack is zeroes,`{{}}`

will pop the stack three times and return 6.) Just like`[…]`

, there are no changes to the stack beyond those made by the referred-to commands.

In addition to writing commands, some implementations allow comments, which go from `#`

to the end of the line. Invalid uses of the `()[]{}<>`

characters are undefined behaviour. Other invalid characters are typically ignored.

Most Mini-Flak implementations output the final state of the stack when the program finishes executing, either interpreting it as ASCII characters / Unicode codepoints, or in decimal (sometimes with an option to choose).

## Computational class

Mini-Flak is known to be Turing complete. The usual proof involves simulating a counter machine.

## Example

Here's a program fragment that swaps the top two elements of the stack:

(({}({}))[({}[{}])])

## Implementations

Mini-Flak is a strict subset of Brain-Flak, and thus is normally implemented using a Brain-Flak interpreter.