esolang

dual tape

Two instructions. One turns a dial of seventeen rules, the other runs whatever the dial points at.

Charles McMarrow, 2021 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: 0

The idea

Charles McMarrow made dual tape in 2021. Every memory cell holds an instruction and a number, so the program and its data share one tape that runs from minus infinity to infinity. There are only two instructions. n turns a rule register one place on and moves to the next cell. x runs the rule the register points at. To print, a program turns the dial to Out Character and runs it; to go back to a rule it just left, it has to turn the dial all the way round.

Read the story

Its sister language, dual tape ez, names every rule by its own letter instead.

The machine

The dial starts at Halt and turns through these rules in this order.

RulesDo
HaltStop
Out Number, Out CharacterPrint item_1 as digits or as a UTF-8 character
In Number, In CharacterRead a line as a number, or one character, into item_1
Add, Subtractitem_1 becomes item_2 plus or minus item_1
Jump, Jump DynamicGo to this cell's number, or to the number in the cell item_1 names
Jump Zero, Jump GreaterGo to item_1 when item_2 is 0, or 0 or more
Read, Read Dynamic, Read Dynamic Instructionitem_2 takes item_1; item_1 takes this cell's number, or the number or instruction in the cell item_1 names
Write, Write Dynamic, Write Dynamic InstructionStore item_1 in this cell, or item_2 in the cell item_1 names, as a number or an instruction

A line is an optional @label, the instruction and an optional number, which is a label, an integer or c and one character for its code. The run starts at the label @. Cells past the program hold n and 0. The specification leaves open how an instruction reads as a number; it is its character code.

Example

The shortest program that prints and stops.

The shortest program that prints and stops. One n turns the dial to Out Number, and x prints item_1, which is 0. Sixteen more n turn the dial round to Halt, and the last x stops.

The Hello World is 469 lines long. Thirteen times it turns the dial to Read, loads a character such as x cH into item_1, turns 8 places on to Out Character and prints it. The truth machine is 92 lines; on 0 it prints 0 and halts, on 1 it prints 1 for ever.

Patterns it teaches

  • Self-modifying code: the Write rules change numbers and instructions in the same cells the program runs from.
  • Turing tarpit: two instructions, and a dial that does the rest.

Further

Self-modifying

Cell-based

Write your own in Run Convert a program from dual tape

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run dual-tape -e '@ n # Truth Machine
n
n
x
n
n
n
n
n
n
n
n
x @zero
n
n
n
n
n
n
n
n
n
n
n
n
n
n
n
x
n
n
x 1
n
n
n
n
n
n
n
n
n
n
n
n
n
@one_loop n
n
n
n
n
n
n
n
n
n
n
x
n
n
n
n
n
n
x @one_loop
@zero n
n
x 0
n
n
n
n
n
n
n
x
n
n
n
n
n
n
n
n
n
n
n
n
n
n
n
n
x' --input '0'
shib manual dual-tape

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/dual-tape.js

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

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