esolang

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

Expected: HI HI HI

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.

CommandDoes
i dAdd or take 1
sSquare
nSet to 0
xSwap v and p
cv = function v called with p
Cv = function p called with v
mCopy the body of function v to slot p, not its variable
o rPrint the character, read one
hHalt

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.

Expected: 0
Expected: Hello World

Patterns it teaches

Further

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 goldfish

Source

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