Befunge

From ArticleWorld


Befunge is a stack-based, reflective, esoteric programming language, with full reflective capabilities. Befunge uses an original flow control system, by using "arrows" ("<", "v", "^" and ">" characters) to control the instructions.

The original design by Chris Pressey was based on an attempt to write a language that is as hard to compile as possible. The initial design limited programs to a grid of 80x25 instructions, thus making it a Turing-incomplete language. Later, this restriction was resolved and the Befunge design in 1998 makes it a Turing-complete language. Befunge also provides support for self-modifying code.

Several extensions and code libraries have appeared for Befunge, even for drawing graphics in a window or working with Internet connections.

The Befunge machine

Befunge is a stack-based programming language, with an instruction space which is torus-like instead of linear, unlike most machines. Instructions include pushing and popping values on and off the stack, support for ASCII character handling and the basic arithmetical operations (addition, subtraction, multiplication, division and modulo) as well as the logical NOT operation.

Examples

>              v
v  ,,,,,"Hello"<
>48*,          v
v,,,,,,"World!"<
>25*,@

This is the typical "Hello, World". It works by pushing the string "olleH" on the stack and popping them back in a LIFO order. The ASCII character "space" (" ") is obtained by multiplying 8 and 4 before being shown on the screen.

A slightly more complex, computing a square root, is following:

v>00p10p>00g:10g\/v
 ^:&<   |:-1p00/2+<
>93*^   >00g.@