Brainfork

From Esolang
Jump to navigation Jump to search

Brainfork is a multithreaded variant of Brainfuck, invented by Asger Ipsen in 2004. Brainfork retains Brainfuck's eight commands and adds a ninth, Y, for forking.

When a Y is encountered, the current thread forks, with the current cell being zeroed in the parent thread, and the pointer being moved one to the right and that cell set to 1 in the child.

Because Brainfork is a proper superset of Brainfuck, all Brainfuck programs that do not contain the letter Y are also valid Brainfork programs with identical semantics.

Because Brainfuck ignores all unknown instructions (such as Y), all Brainfork programs are also valid Brainfuck programs, although they may (of course) behave very differently.

Computational class

Brainfork is Turing-complete through a trivial reduction from Brainfuck, which is known to be Turing-complete.

Implementations

weave.rb with the -Y flag is a Brainfork (and Weave and pbrain and brainfuck) interpreter.

Examples

Use the -Y flag.

With the "Y[-<]" up front, this brainfuck example that normally outputs "Just another brainfuck hacker."

Y[-<]
+++[>+++++<-]>[>+>+++>+>++>+++++>++<[++<]>---]>->-.[>++>+<<--]>--.--.+.
>>>++.<<.<------.+.+++++.>>-.<++++.<--.>>>.<<---.<.-->-.>+.[+++++.---<]>>[.--->]<<.<+.++.++>+++[.<][.]<++.

.. instead outputs "JJusutst a anonoththere r brbraiainnffuucckk hahcackekrer.." If the parent had paused a couple cycles, the execution would have been back in sync and the output would have consisted of unjumbled double characters.

Fork bomb

+[Y+]

This example spawns a thread, then the new thread and the main thread spawn new threads and so on.

External resources