esolang

IfSetThenSet

Eight bits and one command. If this bit is that, set that bit to this.

2024 · Turing complete: no · ●●○ moderate · esolangs.org

Tested with 6 known programs · Test method

Run it

Expected: 0111

The idea

IfSetThenSet has 8 bits of memory and a single kind of command, 8 binary digits long. The first 3 digits name a bit to look at, the 4th is the value it must have, the next 3 name a bit to set and the last is the value to give it. Bit 0 is always 1, so a command that checks it for 1 always fires. Setting bit 0 is how the program talks to the world. Setting it to 1 reads a bit into bit 1, and setting it to 0 prints bit 1.

Read the story

There is no way to stop. When the program reaches its end it starts again. A run ends when the program asks for a bit and the input has none left.

The machine

DigitsMean
1 to 3The bit to check, 0 to 7 in binary
4The value it must have
5 to 7The bit to set, 0 to 7 in binary
8The value to set it to
0001 at the endRead a bit into bit 1
0000 at the endPrint bit 1

Commands are split by -. With 8 bits it is a finite state machine, not Turing complete.

Example

The OR reads two bits into bit 1 and keeps a note in bit 2 when the first is 1.

The OR reads two bits into bit 1 and keeps a note in bit 2 when the first is 1. At the end it clears the note, so it can start over on the next pair. It takes four pairs in one run.

The AND works one time only. A 0 sets bit 2 and nothing clears it, so a later 1 and 1 give 0.

Expected: 1
Expected: 00

The specification also has a truth machine, 01000001-01100000-00010101-00100111. On 1 it prints 1 forever. On 0 it prints 0 and then loops forever in silence, as it never asks for a bit again.

Patterns it teaches

  • One instruction: one conditional set, with I/O hidden in a bit that cannot be set.

Further

Also in Turing tarpits

Write your own in Run Convert a program from IfSetThenSet

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run ifsetthenset -e '00010001-00110101-00010001-01010011-00010000-00010100' --input '00011011'
shib manual ifsetthenset

Source

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

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

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