esolang

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

Expected: 0

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.

CharDoes
> < ^ vMove right, left, up, down
HGo right if the top is above 0, else left (the top stays)
VGo up if the top is above 0, else down (the top stays)
0-9Push a digit
I iRead a character, read an integer
O oPrint the top as a character, as a number (it stays)
nPrint 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

Try this

  1. Change the truth machine so input 0 prints 0 and a newline.
  2. Read two integers and print their sum.
  3. Hard: print the numbers 9 down to 1 with a loop that steers with H.

Further

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 simplefunge

Source

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