The Befreak Programming Language

submited by
Style Pass
2024-04-29 10:00:03

Introduction Hello World Arithmetic Bitwise Operators Stack Combinators Comparisons Inverted Mode Control Flow Input/Output Download Befreak Instruction Reference Links

Befreak is a purely reversible two-dimensional programming language. It was inspired by the Chris Pressey's Befunge programming language. Like Befunge, all Befreak instructions are written as a single character, and execution can flow north, south, east, and west.

The thing that makes Befreak special is its reversibility. Every instruction in Befreak is by its very nature reversible. At any point during execution, if you'd like, you can pause the system, toggle the "reverse" flag, and then upon resuming, the program will run itself backwards from its current state, eventually ending up at the very beginning, where it started. This feature is not accomplished by keeping a history of past states, but simply by virtue of the fact that each individual instruction is reversible. This means that Befreak contains no instructions that can destroy information; this can make programming in the language both challenging and interesting. Hello World We'll begin with the classic "Hello world" program. In Befreak, this is not trivial, so buckle your seatbelts. To help make things easier to follow, I'd recommend downloading the Befreak system, and stepping through the program with the interpreter.

In Befreak, execution always begins at the @ symbol and proceeds east. Thus, the first instruction encountered is "(", which pushes a zero onto the stack (in Befreak, data is manipulated through a stack, a la FORTH). The next instruction, "/", is a mirror that causes the IP (the instruction pointer) to change direction; in this case, it will make IP go north; next is "\", which is another mirror, and in this case causes IP to go west. Next we have the instruction "01", or rather "10" since we're coming from the east: this causes the top item on the stack to be XOR'd with 10 (decimal); since the top of stack was zero, this makes the top of stack 10, which is the ASCII code for newline.

Leave a Comment