esolang

Forked

A two-dimensional language whose only conditional is a fork in the road.

MD XF, 2017 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 4 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: 42

The idea

MD XF made Forked in 2017. An instruction pointer walks the grid as in Befunge, and a stack holds the numbers. There is no if. Instead, a path of - or | runs into a : with the other kind of path leaving on both sides, like a T junction. When the top of the stack is above 0 the pointer turns right, otherwise left.

Read the story

The specification describes more, several instruction pointers made by an IP fork ;, a random fork, and a bomb. The C interpreter in aaronryank/Forked, which is what TIO runs, has one pointer only, and this implementation follows it.

The machine

A stack of 32-bit integers and one register. The pointer starts top left, going right. Walking off the end of a row or column wraps to its start through one blank step.

CommandDoes
> < ^ vTurn
\ /Mirrors; in the interpreter \ turns east to south, south to west, west to north, north to east
:The fork, right when the top is above 0, else left
0-9 A-FPush 0 to 15
i dAdd or take 1 from the top
" s pDuplicate, swap, pop
+ ' * _ m =Plus, minus, times, divide, modulo, equal
$ ~Read a number; a character, -1 at the end
% ?Print the top as a number; and pop
@ !Print the top as a character; and pop
P S U OPop into the register, copy into it, push it, clear it
&End

Example

The second program is the cat.
Expected: cat

The second program is the cat. It reads a character at ~, and the fork turns the pointer west round the loop to print it with @, until ~ gives -1 and the fork turns it east instead, to &.

Patterns it teaches

Further

Two-dimensional languages

Stack-based

Write your own in Run Convert a program from Forked

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run forked -e '67*?&'
shib manual forked

Source

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

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

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