RIfP
Replace If Possible. Every change to a string is also the test that decides where to jump.
ChuckEsoteric08, 2023 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
ChuckEsoteric08 made RIfP in 2023, after /// and Novice. Memory is a set of variables that hold text. The one instruction that does work, !, looks for a piece of text in a variable and replaces its first instance. If it found one it jumps to a label; if not it goes on to the next line. So the replacement is the condition.
Read the story
There is no input. The specification puts the input in the first line of the program, and you change that line to change it.
The machine
| Command | Does |
|---|---|
@x=y | Set the variable x to the text y |
!x y=z a | If x holds y, replace its first y with z and jump to the label a; else go on |
;x | Declare the label x |
$x | Print the value of x |
A z of [] means the empty text. $ prints the value with no line break after it.
Example
The truth machine prints its variable and loops while it can replace a 1 with a 1.
The truth machine prints its variable and loops while it can replace a 1 with a 1. With a 0 in the first line it prints one 0 and stops; with a 1 it prints 1 forever.
A loop that counts by rewriting. Each pass prints the value and turns its first a into b, until there is no a left to find.
The specification proves RIfP Turing complete with a cyclic tag interpreter of 27 lines, which also works. It keeps a ^ in front of the current symbol of the data and of the program and moves it with replacements like ^0=0^. With the data and program the data keeps growing, so the run only ends at a limit.
Patterns it teaches
- String rewriting: one replacement at a time, and its success is the branch.
- Tag systems: the proof is a cyclic tag interpreter.
Further
See also
String-rewriting paradigm
Write your own in Run Convert a program from RIfP
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: rifp.
Command line
shib run rifp -e '@hw=Hello, World!
$hw'shib manual rifpSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/rifp.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org