Alex
Every order is signed - Alex., and what you say yourself is a comment.
Ronald Houkens, 2016 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Ronald Houkens made Alex in 2016. A program reads like a chat. Each command must end with - Alex., and a line that starts with You: is a comment, so the orders look like lines spoken by Alex and the notes look like your side of the talk.
Read the story
The specification is a stub. It calls the memory stack-based, but its three examples and its brainfuck table use numbered cells, labels and jumps, and no stack at all. This implementation builds the commands those use and leaves the stack out.
The machine
| Command | Does |
|---|---|
Say x | Print x; Space and LineFeed stand for a space and a line feed |
Set A1 5 | Set a cell |
Increment A1 Decrement A1 | Add 1, take 1 |
Put A1 Puts A1 | Print a cell as a number or as a character |
Get A1 Gets A1 | Read a number or a character |
Label x GoTo x | Mark a place; jump there |
IfNotZero A1 x | Jump when the cell is not 0 |
IfEquals A1 A2 x | Jump when the two cells are equal |
End | Stop |
Cells are named A1, A2 and so on and start at 0. The program also stops after its last line. In the brainfuck table a loop is a label before the body and an IfNotZero after it, so the body always runs at least once. The specification leaves the end of input open, and in this implementation both reads give 0 there.
Example
The Hello World says one character a line.
The Hello World says one character a line.
The specification calls the next one a count from 5 to 0. The cell does reach 0, but the test comes after the decrement, so the last number printed is 1.
The truth machine compares the number it reads with two cells that hold 0 and 1. On 0 it prints 0 and stops. On 1 it jumps into a loop that prints 1 forever.
Patterns it teaches
- Counter machines: cells to add to and take from, a test for 0 and a jump are enough.
- Camouflage: the program reads as a chat with Alex.
Further
See also
Stack-based
Write your own in Run Convert a program from Alex
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: alex.
Command line
shib run alex -e 'Set A1 5 - Alex.
Label A - Alex.
Put A1 - Alex.
Decrement A1 - Alex.
Say LineFeed - Alex.
IfNotZero A1 A - Alex.'shib manual alexSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/alex.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org