Goldfish
Deadfish with functions. The only place to keep a number is inside a function.
Fergusq, 2014 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Fergusq made Goldfish in 2014 after Deadfish and Deadfish i. Deadfish i has a list of functions but does not say whether they share one accumulator, and the specification shows a truth machine that prints 4 or 1 depending on the answer. Goldfish picks one. Every function keeps its own static variable v, which survives between calls, and gets one argument p. There is no other memory.
The machine
A program is one function a line, its number first. The run calls function 0 with p = 0. Lower case commands work on v, capitals on p.
| Command | Does |
|---|---|
i d | Add or take 1 |
s | Square |
n | Set to 0 |
x | Swap v and p |
c | v = function v called with p |
C | v = function p called with v |
m | Copy the body of function v to slot p, not its variable |
o r | Print the character, read one |
h | Halt |
A function returns its v. Functions without a line are empty, so calling one gives back its own variable, 0 at first. Minsky machines compile into Goldfish, so it is Turing complete.
Example
Function 0 counts its own v up to 1 and calls the function with that number, three times over.
Function 0 counts its own v up to 1 and calls the function with that number, three times over. Function 1 builds 72 from 0 with ii s iiii s and eight more i, prints H, adds 1 for I and ends with a line feed.
The truth machine reads a character and calls the function with that number. Function 48 prints 0 and halts; function 49 prints 1 and calls itself forever.
Patterns it teaches
- Turing tarpit: Deadfish's four commands, a call and a copy.
- Counter machines: the static variables are the counters.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from Goldfish
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: goldfish.
Command line
shib run goldfish -e '0 rc
48 iisiiisdoh
49 niisiiisoc' --input '0'shib manual goldfishSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/goldfish.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org