"Gol><>"
><> with loops, a halt that prints the stack, and fewer bytes for everything.
Sp3000 · Turing complete: yes · ●●○ moderate
Tested with 5 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Sp3000 made Gol><> as "the slightly golfier version of ><>". The fish still swims through a grid of one-character instructions and bounces off mirrors, but the letters that ><> left unused now do work. H prints the whole stack as text and stops, so Hello World is a reversed string and one more character. F opens a counted loop and | closes it, so a loop no longer needs a second row of arrows.
Read the story
Some ><> habits change meaning. | is the end of a block, not a mirror, and _ is an error. A string is read in a single step. Popping an empty stack gives 0 instead of an error.
The machine
A grid with one row per line and no padding, a stack of big integers and floats, and a tape of further stacks. The IP starts at the top left going right and never stops by itself.
| Op | Does |
|---|---|
> < ^ v / \ # | Turn and mirror, as in ><> |
"..." S"..." | Push a string; print it at once |
F...\| W...\| Q...\| | Loop n times, loop while, if |
L B C | Loop counter, break, continue |
R | Repeat the next instruction n times |
i I | Read a character (-1 at the end), a number |
o n N | Print a character, a number, a number and a newline |
H h ; | Print the stack as text and halt, print a number and halt, halt |
M P z m | Minus one, plus one, not, -1 |
Example
The second program reads 5 and loops five times, printing the counter L each time.
The second program reads 5 and loops five times, printing the counter L each time. The third multiplies 1 by the counter plus one, ten times, which is 10 factorial. The last is cat; E skips the ; until the input is spent.
This implementation is a subset. It stops with a reason on x and on the switched instructions for logarithms, trigonometry and random numbers, rather than guess.
Patterns it teaches
- Two-dimensional control flow: the grid of Fish, with blocks laid over it.
- Stack machines: one stack at a time on a tape of stacks.
- Code golf: every spare letter became an instruction.
Try this
- Print the numbers 1 to 10 with
F. - Read a line and print it reversed.
- Hard: print the first ten Fibonacci numbers.
Further
- The reference interpreter, github.com/Sp3000/Golfish, in Python 3, with
doc.txtlisting every instruction - Related: Fish, Starfish
See also
Also in Golfing
Write your own in Run Convert a program from "Gol><>"
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: golfish.
Command line
shib run golfish -e 'iE;o' --input 'cat'shib manual golfishSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/golfish.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language