esolang

Encapsulation

Find a literal string of bits, replace it, repeat. The run ends when the first bit turns to 1.

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

Tested with 10 known programs · Test method

Run it

Expected: 0110

The idea

Hakerh400 made Encapsulation in 2019. The memory is a string of bits, the input with two 0s put in front. A program is a list of literal replacements, with no wildcards. Each step uses the one that matches closest to the start of the memory, and the first one in the source on a tie. The run ends when nothing matches or when the first bit becomes 1, and the output is the memory without its first two bits.

Read the story

That stop rule makes even simple tasks hard. To invert the bits you cannot write 0 - 1 and 1 - 0. The 0s in front would be rewritten first and the run would stop at once, and nothing would tell an inverted bit from one still waiting. The programs first wrap every bit in a longer code, then work on the codes, then unwrap them and set the first bit to 1. The specification shows it is Turing complete by encoding Thue in it.

The machine

DefinitionDoes
0101 - 110Replace the first 0101 with 110
<001 -Delete 001 at the start of the memory
> - 10Add 10 at the end
<0> - 1Replace a memory that is exactly 0
- 01Put 01 at the start, as the empty pattern matches there

Definitions are split by spaces, line breaks or ;. Input and output are written as the characters 0 and 1.

Example

The empty program is the cat.

The empty program is the cat. The bit inverter wraps each bit, flips it inside its wrapper and takes the wrappers off again.

Expected: 1001

Extracting the first bit needs no wrapping. Each step swallows the bit after the first input bit, until only 00 and that bit are left and nothing matches.

Expected: 1

The truth machine on 0 sets the first bit at once. On 1 it can never stop, because 1 - 11 keeps growing the memory and the first bit stays 0.

Expected: 0

The Hello, world! eats the input one bit a step, then puts 105 bits in front of the last 0. The first of them is 1, so the run stops, and the 104 bits after the first two spell Hello, World! in ASCII with the lowest bit of each byte first.

Patterns it teaches

  • String rewriting: with literal patterns only and a stop rule that guards one bit.

Further

String-rewriting paradigm

Write your own in Run Convert a program from Encapsulation

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run encapsulation -e '<000 - 100
1 - 11' --input '0'
shib manual encapsulation

Source

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

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

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