Simplefunge
Befunge with the clever parts taken out: arrows, a stack, and two ways to dig into it.
CrazyM4n, 2014 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 2 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
CrazyM4n meant to cross Brainfuck with Befunge. What came out in 2014 was a smaller Befunge. The pointer starts at the top left and follows arrows across a grid of characters, running each command it lands on.
Read the story
There is no string mode, no put and get, no self-modification. What is left is a stack and two odd commands, | and ., that reach into the middle of it. The author argues these two make the language Turing complete, since any item can be brought to the top and put back.
The machine
One stack of integers and a pointer that starts top left, moving right. It wraps at the edges. Popping an empty stack gives 0.
| Char | Does |
|---|---|
> < ^ v | Move right, left, up, down |
H | Go right if the top is above 0, else left (the top stays) |
V | Go up if the top is above 0, else down (the top stays) |
0-9 | Push a digit |
I i | Read a character, read an integer |
O o | Print the top as a character, as a number (it stays) |
n | Print a newline |
+ - * / | Arithmetic; - and / work top by second |
` ! & | Drop, dup, swap | |
\| | Pop n, move the item at depth n (top is 0) to the top |
. | Pop n, move the next item down to depth n |
@ | End |
The specification does not say whether o and O pop. The truth machine below only loops forever on input 1 if o leaves the value in place, so they do not pop.
Example
The truth machine.
The truth machine. i reads the number and v sends the pointer down to the V. On 0 it goes down: 0 pushes a zero, o prints it and @ ends. On 1 it goes up into a small loop of ^, o and v that prints 1 forever.
Patterns it teaches
- Two-dimensional control flow:
HandVare the only branches, and a loop is a closed path of arrows. - Stack machines:
|and.turn a plain stack into something closer to random access memory.
Try this
- Change the truth machine so input 0 prints
0and a newline. - Read two integers and print their sum.
- Hard: print the numbers 9 down to 1 with a loop that steers with
H.
Further
See also
Two-dimensional languages
Stack-based
Write your own in Run Convert a program from Simplefunge
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: simplefunge.
Command line
shib run simplefunge -e '>IO@' --input 'x'shib manual simplefungeSource
- Module
langs/stack/ports.js- Interpreter
langs/stack/simplefunge.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org