esolang

Versert

What happens to Befunge when you take away its stack? Two registers and a pointer into the code are left.

Kang Seonghoon, 2005 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 3 known programs · Hello World on Try It Online: identical except the line end · Test method

Run it

Expected: Hello, world!

The idea

Kang Seonghoon made Versert in 2005. The name comes from 버섯, the Korean word for mushroom. It starts from a question: what if Befunge had no stack? The code still sits on a grid that the instruction pointer walks and wraps around. All the data now lives in two registers, A and B, and in the grid itself, which a data pointer can read and write.

The machine

The instruction pointer starts at the top left, heading east. The data pointer starts at the top left too, and both registers start at 0.

CommandDoes
0-9Set A to the digit
+ - *B becomes B + A, B - A, B * A
~Swap A and B
` > | Swap A and B if A is greater, or if A is smaller
/ \Mirrors that turn the instruction pointer
#Skip the next cell if B is 0
. :Print A as a character, or as a number
, ;Read a character or a number into A; at the end of the input A stays as it is
{Load the cell under the data pointer into B
}Store B in the cell under the data pointer
\|Move the data pointer A cells right and B cells down
@Stop

The only test is #, so every decision has to end up as a 0 in B.

Example

TIO's hello world builds each letter from the one before.

TIO's hello world builds each letter from the one before. 6~6* makes 36 in B and } stores it in the top left cell, so { can load 36 back later. 2* doubles it to 72, ~. prints H, and so on.

Expected: meow

A cat program in two lines. The loop runs east along the top and west along the bottom. 0~1 clears B and sets A to 1, -~ leaves -1 in A and 1 in B, and , reads a character over the -1. Then + adds it to B. Only at the end of the input, when A is still -1, is B now 0, and the # jumps over the mirror onto @. Otherwise the mirrors bring the pointer up to ., which prints the character.

Patterns it teaches

Try this

  1. Print Hi with . only.
  2. Read two digits with ; and print their product with :.
  3. Hard: print the input backwards, storing it in the grid.

Further

Self-modifying

Two-dimensional languages

Write your own in Run Convert a program from Versert

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: versert.

Command line

shib run versert -e '#/#.0~1\ 
@\#+,~-/' --input 'meow'
shib manual versert

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/versert.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org