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
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.
| Cells | Name | Does |
|---|---|---|
0 n | MVR | Move the read head n cells right |
1 n | MVW | Move the write head n cells right |
2 | INC | Add 1 at the write head; the read head moves one cell |
3 | DEC | Take 1 at the write head; the read head moves one cell |
4 x y | IF | Move the read head 3 cells if x is above 0, else y cells |
5 v | CPY | Write v at the write head |
6 z | OutP | Print 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.
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
- Self-modifying code: the loop counter is the operand of the loop's own test.
Further
See also
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 rwlrSource
- 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