esolang

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

Expected: Hello, World!

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:

CharDoes
a–fPush 10 to 15
' sPush the next cell's character; pop a value into the next cell
;Skip everything up to the next ;, in no time (a comment)
j kJump over n cells; run the next instruction n times
[ ] r xTurn left, turn right, reverse, set the direction to any vector
wCompare two numbers and turn left, go on, or turn right
n qClear the stack; quit the whole program
{ } uOpen and close a stack on the stack of stacks, move values between them
tSplit: a second pointer starts here going the other way
yAsk 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:

Expected: AB

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:

Expected: !!

Patterns it teaches

Try this

  1. Print Hello with k and one ,.
  2. Use t to make two pointers print different letters.
  3. Hard: use x to send the pointer diagonally across a program, and let it wrap.

Further

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-98

Source

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