Amelia
Genes of numbers read three at a time, made to be bred by mutation and selection rather than written.
Turing complete: unknown · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Amelia is the child of Iris. Like Iris it has no syntax errors and no premature exit, so that programs can be made by random mutation and kept by selection. A program is a chromosome. Each gene is a list of numbers read in triplets called codons, and each number is a base. There are only two kinds of gene. MOD sets a register and MOV moves the pointer, and the rest of the gene is an expression.
The machine
| Gene | Does |
|---|---|
even,r,k, then codons | MOD sets register r, or the register r points to when k is odd, to the expression |
odd,g,n, then codons | MOV, if the expression is true, goes to gene g, or runs n genes there and comes back |
Each codon of the expression is kind,x,ref. By ref mod 3 the item is x itself, register x, or the register that register x points to. Whether an item is a value or an operator follows from how many of each came before, so every list of codons makes a well-formed prefix expression. MOD has the operators + - * / ** % and MOV has == > < >= <= != and or not xor.
The chromosome loops. A run ends when something is divided by 0, when a MOV jumps to its own gene, or after 999 genes, and then every register is printed. The specification's interpreter is in Perl and hands each operation to eval as text. This implementation follows that, octal numbers included.
Example
The Fibonacci from the specification, on one line without its comments.
The Fibonacci from the specification, on one line without its comments. Register 0 says where the next number goes and registers 1 and 2 point at the two before it. Gene 7 ends the run by jumping to itself once register 25 is set.
The codons are read last first, so 7, 2 and the operator / make the prefix expression / 2 7, which is 2 divided by 7. Nothing stops this one, so it ends after 999 genes.
Perl reads a number with a leading 0 as octal. A base of 010 adds 8, and a base of 08 is an illegal octal digit, which the interpreter takes for a division by 0 and so ends the run.
Patterns it teaches
- Artificial life: a genome to mutate and select, not a program to write.
- Every text runs: any list of numbers is a chromosome that runs.
Further
See also
Also in Artificial life
Write your own in Run Convert a program from Amelia
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: amelia.
Command line
shib run amelia -e '0,0,0, :assigns a value to register 0,
0,5,0,; :the value is 5'shib manual ameliaSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/amelia.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org