A family of esoteric programming languages including Unefunge, Befunge and Trefunge, the 1-, 2- and 3- dimensional variations on the Fungeoid theme. Befunge is the most popular; Unefunge is used occasionally, and Trefunge is, frankly, ridiculous. The key feature of Befunge (and its relatives) is that program flow can go in any direction on a grid of single-cell instructions; commonly moving in the cardinal directions (although diagonals and 'knight's moves' and, in fact, any combination of Δy/Δx are permitted.)

Theoretically, Funge98 scales up to large projects, what with its module loading functionality. In actuality, though, that's no fun at all, and most Befunge activity consists of squashing trivial algorithms into the smallest possible code space.

All Funge source code is plug-ugly. One reason for this is that all commands in Funge are single ASCII characters, a la BrainF*ck. For example, the ^, v, < and > commands set the Befunge instruction pointer moving up, down, left and right respectively.

Funge data may be stored in program space (as no distinction is made between code and data,) or may be placed on the globally accessible stack. Virtually all operations work destructively with the stack, which is pretty good because you get Reverse Polish notation for free.

A common idiom to print out a null-terminated string stored on the stack, is: >:#,_@

Tracing program execution through the first iteration of this loop yields:

  1. > Start program movement to the right (which is the default anyway.)
  2. : Duplicate the topmost item on the stack; eg, the first character of the string.
  3. # Leapfrog over the next command character (landing on the underscore.)
  4. _ 'Horizontal If' -- Pop from the stack. Go right if it's 0, left otherwise. We've got a character, so we go left.
  5. , Pop from the stack, and print it as an ASCII character.
  6. # Leapfrog over the : command to land on the >...

The @ character is an 'end of program' marker. Funge program space wraps around, so if there were no @ there, the program counter would hit the first command again, and print any more strings that were on the stack. And anything else that might be there. And then it would sit in an infinite loop.

Why would any sane person want to write in this language? The only answer I can give is:

>#,~:'m`|`m' :~,<
  | `z':[:'a1-`!|
^ [#,d#+ -#d,# #<

Log in or register to write something here or to contact authors.