esolang

RCEM

True, false and maybe on a tape, one big number beside it, and a loop that runs when a coin says so.

Feuermonster, 2008 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: A

The idea

Feuermonster made the Random Code Executation Machine in March 2008. Its tape holds trits, so a cell is 0 for false, 1 for true or 2 for maybe. Beside the tape sits the I-Cell, one integer of any size and sign. The tape can be read into the I-Cell as binary and written back, and that is how numbers and characters get made.

Read the story

Two commands use chance. x_ sets the cell to 0, 1 or 2 at random, and [...] runs its code only when a coin falls on 1, or when the cell is 2.

The machine

CommandDoes
r5 l5Move the pointer 5 cells right or left
s2Set the cell to 2
o_ i_Print the cell; read a number into it
x_Set the cell at random
^1 +1XOR or AND the cell with the one 1 to the right
c_ ++ --Swap 0 and 1; add 1; take 1, all modulo 3
21When the cell is 2, set it to 1
m+ m-Add 1 to the I-Cell or take 1
mp mo miPrint the I-Cell as a number or a character; read it
m::0::3Read cells 0 to 3 as binary into the I-Cell
z::0::3Write the I-Cell's bits to cells 0 to 3, lowest first

The loops are (...) while the cell is 0, {...} while it is 1, /...\ while it is 2, <...> while the I-Cell is not 0, and [...] while the cell is 2 or the coin falls on 1. The specification carries a Common Lisp interpreter, and this implementation follows it. A space is an error there too, so a program is one unbroken line.

Example

The I-Cell counts the cells up to the 1 at cell 65, then prints that count as a character.

The I-Cell counts the cells up to the 1 at cell 65, then prints that count as a character.

Cells 0 to 3 hold 0, 1, 0, 1, which is 5 in binary.

Expected: 5

Five m+ make 5, and z::0::2 writes its bits 1, 0, 1 into cells 0 to 2.

Expected: 101

The x_/x_\o_ draws again while it draws a 2, so it prints 0 or 1. Chance comes from a fixed seed, so one program always draws the same.

Patterns it teaches

Further

Cell-based

Write your own in Run Convert a program from RCEM

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run rcem -e 's2o_'
shib manual rcem

Source

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

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

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