From Esolang
Jump to navigation Jump to search

Unfuck is an esoteric programming language designed by User:Andrew_Melrose in 2015. The language is based on Urban Müller's Brainfuck language, but it takes a different spin on how control flow works. It has an infinite tape with 8 bit wrapping cells.

All instructions for the exception of [ and ] still remain. Instead a new set of instructions have been put in their place.

There is only one instruction which carries out a conditional test on the current cell, from that and it's complimentary instructions, a variety of control flow structures can be composed. Below is a list of those instructions and a description of what they do;

?   Tests the current cell to determine if it is non-zero, if so, skip the next instruction.
(   Increments the block depth counter.
)   Decrements the block depth counter.
~   Swaps ( and ).
!   Inverts the block depth counter.
^   Does the same as ~ and !, plus reverses the program counter.

These instructions work by manipulating the way the interpreter treats the rest of the program depending on the value held in the block depth counter. If the value is positive, then all of the instructions for the exception of the parenthesis will be treated as no-ops. With that said, the parenthesis can also be used to comment out code.


So, how does one build a while loop?

  Execute some code until condition is met

Most often than not all we want to do is test a cell and execute some code once. Here is an if structure.

  Some code to execute once.

These are just two out of a dozen or more structures that can be built. It is left as an excercise for the reader to discover the rest.

It is good practice to only place standard Brainfuck code when the block depth is zero, rather than when it is negative. This may become an important rule in a future implementation.

Computational class

Unfuck is Turing complete by reduction to Brainfuck.

[  =  (^~)~(~?!)((
]  =  ))(^)

External Resources