esolang

Malfunge

Befunge where the arrows are retroreflectors. Run into the open side of one and you bounce straight back.

ArthroStar11, 2021 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: 0

The idea

ArthroStar11 made Malfunge in 2021, after Befunge and Malbolge. The field is 256 by 256 cells and the pointer starts at the top left moving right, as in Befunge. The arrows work differently. An arrow turns the pointer to its point only when the pointer comes in from a slope. Coming in from the open side sends it back the way it came, and coming in from the point makes a test. One arrow can be a turn, a mirror and an if.

Read the story

Arithmetic moves too. There are five stacks, and an operator pops its two numbers from the current stack but pushes the result onto the next one. A program follows its own results around with S.

The machine

CharDoes
> < ^ vFrom a slope, turn to the point; from the open side, go back; from the point, test
\| _Paddles. Go back when hit flat on, test when hit edge on
/ \Mirrors
o ?Skip the next cell; turn at random
0 to 9Push a digit
P M T D mPop a, then b, and push b+a, b-a, b×a, b/a or b mod a onto the next stack
S sMove to the next or the previous of the five stacks
, .Read a character or a number
; :Print a character or a number
"String mode
I i dPush 1 if b > a; push 1 if a is 0; duplicate
@End

A test pops a value. A sideways arrow and the paddle _ send the pointer down on 0 and up otherwise. An upright arrow and the paddle | send it right on 0 and left otherwise. Every stack holds at most 1000 numbers of 32 bits.

Example

The truth machine.

The truth machine. . reads the number and o jumps over the first >. The loop prints the number, turns down at v and left at <, and meets the lower > from its point. There the test sends a 0 down to @ and anything else up into the loop again.

Strings push their characters, the first one deepest. Operators leave their result on the next stack, so S has to follow it there before : prints 3 + 4.

Expected: hi
Expected: 7

The Hello World pushes a 0 and the text backwards, then prints and tests in the same loop. It prints the 0 before the test sees it, so its output is hello world! followed by a NUL byte.

Patterns it teaches

Further

Two-dimensional languages

Stack-based

Write your own in Run Convert a program from Malfunge

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run malfunge -e '.o>dd:v
  >   <
  @' --input '0'
shib manual malfunge

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/malfunge.js

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

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