Befunge-98
Befunge without walls. The grid never ends, a program can hold a stack of stacks, and one instruction splits the pointer in two.
Chris Pressey, 1998 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 7 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Befunge-93 was meant to be hard to compile, but its 80 × 25 grid made it a bounded machine. In 1998 Chris Pressey and the Befunge mailing list wrote Funge-98, a much bigger specification. It lifts the size limit and turns the toy into something closer to a real language.
Read the story
Funge-98 is a family. Unefunge runs on a line, Befunge on a plane and Trefunge in a cube; the instructions are the same, only the number of directions changes. This entry covers the plane.
Three ideas stand out. Funge-Space is unbounded, so p can write a cell a billion steps away. A pointer that runs off the program does not fall off: it wraps back along its line to the far side, which works for any direction, even a diagonal one ("Lahey-space"). And t splits the pointer. Both pointers then run in turn, each with its own copy of the stacks.
The machine
Everything from Befunge-93, plus:
| Char | Does |
|---|---|
a–f | Push 10 to 15 |
' s | Push the next cell's character; pop a value into the next cell |
; | Skip everything up to the next ;, in no time (a comment) |
j k | Jump over n cells; run the next instruction n times |
[ ] r x | Turn left, turn right, reverse, set the direction to any vector |
w | Compare two numbers and turn left, go on, or turn right |
n q | Clear the stack; quit the whole program |
{ } u | Open and close a stack on the stack of stacks, move values between them |
t | Split: a second pointer starts here going the other way |
y | Ask the system: dimensions, the pointer's position, stack sizes and more |
Spaces take no time, and in string mode a run of spaces pushes one space. Anything unknown, and the parts this implementation leaves out (fingerprints, files, system calls), makes the pointer reverse.
Example
The shortest well-known Hello World uses k:
The shortest well-known Hello World uses k:
String mode pushes the message backwards, with an extra 9 at the bottom. c pushes 12, and k runs the next instruction, ,, twelve times. Then the pointer moves on to the , itself, which prints a thirteenth character, the !. The 9 is left over.
Going west from the first cell wraps round to the far end of the line:
Read it right to left: ;em piks; is skipped, 'A, prints A, 'B, prints B, a, a newline.
Two pointers at once. t starts a second pointer going west, and 2j makes the first one jump over the @, that the second one uses:
Patterns it teaches
- Two-dimensional control flow: wrapping now works on any line through space, not only rows and columns.
- Self-modifying code and code as data:
'andsread and write the cell right in front of the pointer. - Stack machines: the stack of stacks gives each block its own stack and its own origin for
gandp, like a call frame. - Turing completeness: unbounded space makes Befunge-98 universal, which Befunge-93 is not.
Try this
- Print
Hellowithkand one,. - Use
tto make two pointers print different letters. - Hard: use
xto send the pointer diagonally across a program, and let it wrap.
Further
- esolangs.org/wiki/Funge-98
- The Funge-98 specification by Chris Pressey (catseye.tc).
- Related: Befunge-93, Seed, which generates Befunge-98 programs.
See also
Multi-dimensional languages
Self-modifying
Write your own in Run Convert a program from Befunge-98
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: befunge-98.
Command line
shib run befunge-98 -e '#@~,' --input 'echo'shib manual befunge-98Source
- Module
langs/tio/ports.js- Interpreter
langs/tio/befunge-98.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org