esolang

Expansion

One line of memory. Every bracketed word in it is rewritten at once, turn after turn, until no bracketed word is left.

None1, 2024 · Turing complete: unknown · ●○○ easy · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: Hello, World!

The idea

None1 made Expansion in 2024. A program is a list of rules and one memory string. Like Thue it rewrites text, but it does not pick one match at a time. Each turn rewrites every bracketed word in the memory, from left to right, and what a rule puts in is only looked at in the next turn. When the memory holds no bracketed word any more, it is printed and the run ends.

Read the story

There is no input. A program that needs a value has it written into the memory by hand.

The machine

LineDoes
[word]=textA rule; the bracketed word becomes the text
*memoryThe last line, the memory string to start from

A bracketed word runs from a [ to the next ]. One without a rule stays as it is, so it is still a bracketed word in the next turn. The specification's interpreter only stops when no bracketed word is left, and such a program runs forever. A lone [ or ] does not count.

Example

The second is the truth machine, with the input written into the memory.
Expected: 0

The second is the truth machine, with the input written into the memory. On 0 the bracket becomes 0 and the run ends. On 1 it becomes 1[1], which holds the bracket again, so the memory grows by one 1 each turn and is never printed.

The A+B program has a rule for each of the 100 pairs of digits, from [0 0]=0 to [9 9]=18. With *[3 4] as its memory it prints 7.

The last example in the specification doubles. [0]=A, [1]=[0][0] and so on up to [19]=[18][18]. From [19] that makes 2^19 = 524,288 A's in 20 turns, half the 1,048,576 its title says. Started lower, the same rules print 1,024 A's from [10] and 32,768 from [15].

Patterns it teaches

Further

String-rewriting paradigm

Write your own in Run Convert a program from Expansion

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run expansion -e '*Hello, World!'
shib manual expansion

Source

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

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

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