Challenges by default ask for submissions that are either functions or complete programs. Historically Brain-Flak submissions have been complete programs because there is no way to define functions like in other languages.

However code Snippets in Brain-Flak can be thought of as functions because they do return a value.

For example:

In Brain-Flak,


is arguably the same thing as


in Python.

The latter would be a valid answer if the question was a question to output 4 so why not the former?

The argument for functions with input is a little more tenuous since the Stack is more like a global variable than a input, but one might say that



lambda x:x**2

are equivalent and thus the former is also a function. To what extent can snippets written in Brain-Flak (and other Flaks such as Brain-Flueue or Micro-Flak) be considered functions for PPCG submissions?

  • 7
    \$\begingroup\$ I don't see why it is lambda: 4 rather than just 4. There is no way to reference the function without using the entire thing so it's much rather a code snippet \$\endgroup\$ – Downgoat Jan 4 '17 at 6:38

However code Snippets in Brain-Flak can be thought of as functions because they do return a value.

I would disagree with that. Code snippets in brain-flak don't return a value, they simply evaluate to a certain value. To reiterate what some other users have already said,


is not equivalent to

lambda: 4

in python, it's equivalent to


They both produce a value, and have no side effect. You can do things with this value, such as


in python, or


in brain-flak, but it's not a function by itself. Similarly, your other example is equivalent to:

input() ** 2


lambda x:x**2

The crucial difference here is that in the python example, it defines a block of code that can be saved and reused later, while the brain-flak code is just a snippet that evaluates to a certain value. Since brain-flak has no ability to save and reuse a piece of code, I would say it has no functions. The same would apply to the various flak-variations (mini-flak, brain-fleue), brainfuck, and other similar tarpits.

So I would propose that brain-flak has no functions, and treating snippets as functions should not be allowed.

On a related note, I found the following proposed default IO methods on meta while I was thinking over this answer:

Given the way brain-flak implicitly pushes all input to the stack, and implicitly prints all values left on the stack, if brain-flak had functions it wouldn't make any difference. A hypothetical function in brain-flak would be the same length as the full program with standard IO.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .