Goldfish

From Esolang
Jump to navigation Jump to search
Goldfish
Paradigm(s) imperative
Designed by User:Fergusq
Appeared in 2014
Computational class Turing complete
Reference implementation [1]
Influenced by Deadfish i, Deadfish
File extension(s) .gfi

Goldfish is an esoteric programming language by User:Fergusq inspired by Deadfish i. Only way to store data is creating functions and static variables inside them.

Design

0<++]
1<-.
2<-.[2

Truth-machine in Dfi, if there is only one accumulator. Change the first line to 0<+] if the input is 0.

Goldfish is heavily inspired by Deadfish and Deadfish i. Dfi resembles Goldfish in that it contains a list of functions (called classes).

0<+++] # calls function 3
3<+. # prints something
0<++]
1<.
2<+.-[2

Truth-machine in Dfi, if there are many accumulators and they don't reset when function is called again. (Goldfish semantics). Change the first line to 0<+] if the input is 0.

The author tried to make a truth-machine implementation in Dfi, but it turned to be impossible due to ambiguity in the specification: it is not clear whether all functions share the same accumulator or have each their own. The above program may print 4 or 1.

0<++]
1<.
2<+.[2

Truth-machine in Dfi, if there are many accumulators and they reset when function is called again. Change the first line to 0<+] if the input is 0.

Goldfish is based on possible semantics of Dfi: every function has it's own accumulator which does not reset when function is called again.

Goldfish commands are more like Deadfish than Dfi: i, d, s, o instead of +, -, >, .. That is because all commands can be written both in upper case and lowercase depending on which variable they modify.

Overview

A source file is a list of function declarations. For example, the following declares two functions, 0 and 1. It prints three times HI.

0 ic n ic n ic
1 niisiiiisiiiiiiiioioniiisio

Function number can be positive or negative. All undefined functions are empty at the begining. There are no comments, but unused functions can be used as such.

Each function has it's own static variable (called v) and receives one argument (called p). All commands which modify v are in lower case and all which p in UPPER CASE. Function returns the value of v.

99 calls 1 three times ~ should print 1 2 3
0 ico n ico n ico
1 i

At the begining, function 0 is called with argument 0.

Commands

Command Description Pseudocode
i Increments v. v++
I Increments p. p++
d Decrements v. v--
D Decrements p. p--
s Squares v. v *= v
S Squares p. p *= p
n Sets v to zero. v = 0
N Sets p to zero. p = 0
x Swaps v and p. tmp = p; p = v; v = tmp
X Same as above. tmp = v; v = p; p = tmp
c Calls function in address v with argument p. v = f[v](p)
C Calls function in address p with argument v. v = f[p](v)
m Copies function v to slot p. Does not copy the static variable. f[p] = f[v]
M Copies function p to slot v. Does not copy the static variable. f[v] = f[p]
h Halts the program. halt()
H Same as above. halt()
o Prints character v. print(v)
O Prints character p. print(p)
r Reads a character and puts it to v. v = read()
R Reads a character and puts it to p. p = read()

Examples

Hello world

0 iisiiiisiiiiiiiioniiisisioiiiiiiiooiiioniisiisddddoniisiiiiisiiiiiioniiisiisddddddddddoiiioddddddoddddddddoniiisio

Cat program

0 ronc

Truth-machine

0 rc
48 iisiiisdoh
49 niisiiisoc

Computational class

Goldfish is Turing complete as Minsky machines can be compiled into it. See external resources for proof.

See also

External resources