esolang

RWLR

One tape holds the program and the data. A read head runs it, a write head changes it.

Tslil Clingman, 2008 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 42

The idea

Read Write Left Right is a tape language with self-modifying code. The specification says Tslil Clingman created it in mid 2007 and realised it in mid 2008. Program and data share one tape of integers, and there are two heads. Only the read head reads commands and data; only the write head changes cells. So a program rewrites its own commands as it runs.

The machine

Both heads start on the leftmost cell. The read head runs the command under it and then moves two cells right, unless the command moved it.

CellsNameDoes
0 nMVRMove the read head n cells right
1 nMVWMove the write head n cells right
2INCAdd 1 at the write head; the read head moves one cell
3DECTake 1 at the write head; the read head moves one cell
4 x yIFMove the read head 3 cells if x is above 0, else y cells
5 vCPYWrite v at the write head
6 zOutPPrint the cell z cells right of the 6

Negative n and y move left. The author's Python interpreter is in the specification and this implementation follows it. The machine halts when a step leaves both heads where they were, or when the read head runs off the right end of the tape.

Example

The first prints the cell four to the right of the 6, then 0 0 moves nothing and halts.
Expected: 36
Expected: 7

The first prints the cell four to the right of the 6, then 0 0 moves nothing and halts.

The other two are the addition programme, with A and B in cells 17 and 19. It copies B into cell 5, which is the test of its own IF. Each round adds 1 to A, takes 1 from B and copies B into the IF again. When the IF finds 0 there, it jumps to a 6 that prints A. On the interpreter's own tape, A = -4 and B = 40, that takes 447 steps.

Patterns it teaches

Further

Also in Turing tarpits

Write your own in Run Convert a program from RWLR

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run rwlr -e '1,5,0,16,4,0,18,1,12,2,1,2,3,1,-19,0,-15,3,5,4,0,-16,6,-5,0,0'
shib manual rwlr

Source

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

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

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