esolang

Realm

Memory is a graph where every node has two arrows and nothing else. A program only redraws arrows.

Hakerh400, 2019 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: Hi

The idea

Hakerh400 made Realm in 2019. The aim was a language as simple as brainfuck but more essential than lambda calculus. While writing an interpreter for Functasy, its designers noticed that any state of a Functasy program can be held in Realm. Memory is a directed graph. Each node has exactly two pointers, 0 and 1, and holds no value at all. Two nodes are equal only when they are the same node.

Read the story

An address is a string of bits, followed from the root node one pointer at a time. The empty address is the root itself. Input is not an instruction. A ? in any address reads the next input bit, so 10??1? can name eight different nodes.

The machine

At the start there is only the root, and both its pointers point back to it.

InstructionDoes
A.BMake the pointer at A point to the node at B
A.B.CMake a fresh node that points to B and C, and put it at A
AWrite the bits of A
A.B( ... )Repeat the body while A and B are the same node

The parser is greedy, so A.B followed by ( is always a loop. The right hand side is found first, which is why 1.0.1 leaves the old root[1] as the fresh node's pointer 1.

Input and output are streams of bits. As in the examples, each input byte becomes 8 bits, lowest first, each one after a 1, and zeros follow the input for ever. Output bits fill bytes the same way, without the 1s.

Example

The short cat points root[0] at a fresh node.

The short cat points root[0] at a fresh node. Its loop reads a bit and compares root[bit] with the root, which holds for 1 and fails for 0. So the loop runs once for each 1 that comes before an input bit, and its ? copies that bit to the output. After the input it reads 0 and stops.

Expected: abc

On 1 the truth machine writes the 8 bits of 1 for ever. On 0 the loop never starts, and the last line writes the 8 bits of 0.

Expected: 0

Patterns it teaches

Further

Also in Rewriting

Write your own in Run Convert a program from Realm

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run realm -e '0.. ?.(?)' --input 'Hello, world!'
shib manual realm

Source

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

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

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