Befunge
Befunge is an esoteric, reflective, stack-based programming language notable for its two-dimensional program space and instruction pointer that can move up, down, left, or right. Developed by Chris Pressey in 1993, its name is derived from the phrase "Before Fun".
The key characteristic of Befunge is its grid-based execution model. A Befunge program is arranged on a two-dimensional grid of characters, typically 80 columns by 25 rows. Each character in the grid represents an instruction. The instruction pointer (IP) traverses this grid, executing the instruction at its current location.
Unlike traditional linear programming languages, the direction of the IP's movement is not fixed. Instructions exist to change the direction of the IP, allowing it to move up (^), down (v), left (<), or right (>). Conditional branching is achieved by instructions that redirect the IP based on the value of the top element on the stack.
Befunge features a single stack for data manipulation. Instructions exist to push values onto the stack, pop values off the stack, perform arithmetic operations, and duplicate or swap stack elements. Input and output operations are also stack-based.
The language also supports a "stringmode," where characters are pushed onto the stack until stringmode is exited. This mode is toggled by the "
instruction.
Befunge is reflective, meaning that a program can modify its own source code during execution. The p
instruction allows a program to put a character value into a specific location in the grid, effectively altering the program itself. The g
instruction retrieves the character at a given location. This capability makes Befunge programs capable of complex and self-modifying behavior.
Due to its unusual execution model and self-modifying capabilities, Befunge is often used as a challenge for programmers and is frequently featured in esoteric programming language contests. Its Turing completeness has been demonstrated.