esolang

A=B

One line of text, and a list of replacements tried from the top until none fits.

Artless Games, 2022 · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: ABACBCAB

The idea

A=B, said "A to B", is the language of the puzzle game of the same name by Artless Games, released on 29 March 2022. Like ///, it has one instruction, text replacement. A program is a list of rules, one to a line. Each step takes the first rule whose left side is in the text and replaces the first place it occurs with the right side. Then the search starts again from the top. When no rule fits, what is left is the output.

Read the story

The game adds keywords world by world. They tie a rule to the start or the end of the text, move text there, stop with an answer, or let a rule work only once.

The machine

RuleDoes
A=BReplace the first A with B
(start)A=B (end)A=BOnly an A at the start, or at the end
A=(start)B A=(end)BTake the first A away and put B at the start, or at the end
A=(return)BStop, with B as the output
(once)A=BWork only once in a run
#A comment to the end of the line

The input is one line of text. The only output is the text at the end, so a program that never stops prints nothing.

Example

Each step the first rule that fits wins, so every a turns into A before the first b does, and the run…

Each step the first rule that fits wins, so every a turns into A before the first b does, and the run makes 8 replacements.

Expected: Hello, world!
Expected: 0

An empty left side is in every text, so the Hello world stops at once. The truth machine returns 0 on 0. On 1 it makes 11, 111 and so on without end, and as nothing is printed before the end, it prints nothing at all.

Patterns it teaches

  • String rewriting: ordered rules, the first that fits wins, as in a Markov algorithm.

Further

String-rewriting paradigm

Self-modifying

Write your own in Run Convert a program from A=B

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: a-b.

Command line

shib run a-b -e 'a=A
b=B
c=C' --input 'abacbcab'
shib manual a-b

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/a-b.js

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

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