Jellyfish
A two-dimensional language inspired by J, where every function finds its arguments by looking south and east.
Turing complete: yes · ●●● hard
Tested with 6 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
The name joins Jelly, a golfing language inspired by J, and Fish, a two-dimensional language. A program is a grid. Each function on it takes its arguments from the nearest item below it and the nearest item to its right, skipping blank cells. With both it is binary, with one it is unary. Only the item in the top left corner is evaluated, together with everything it needs.
Read the story
Nothing is printed by default. The functions p and P print their argument and pass it on, so they usually sit in the corner.
The machine
| Code | Does |
|---|---|
12 'c "text" | A number, a character, a string (a list of characters) |
i I | An input line read as a value, as text |
p P | Print as a value, print as a matrix |
+ - * % | Add, subtract, multiply, divide; alone, abs, negate, sign, reciprocal |
r | The range from 0 |
# , ; | Length, join, pair |
< > | Compare; alone, decrement, increment, head, tail |
B V E S X | Block or turn the search for arguments |
Arithmetic works on every element of a list. The left argument is the one from the south, so - and % compute the east value minus or divided by the south value.
Example
r5 is the range 0 to 4.
r5 is the range 0 to 4. p prints it as a value, in brackets; P prints it as a row. In the last program + has a 3 to its east and a 5 to its south, so it adds them, and p prints the sum.
This implementation is a subset, after the Python interpreter in the iatorm/jellyfish repository, which TIO runs. It has values, input, the search for arguments and the common functions. The operators, which build new functions from functions, and the rarer functions stop the run with the reason.
Patterns it teaches
- Code golf: where an item sits says what it is applied to.
- Two-dimensional control flow: data flows north and west through the grid.
- Combinators: the operators combine functions the way J's adverbs do.
Try this
- Print the sum of 12 and 30.
- Read a number and print its square.
- Hard: print the length of an input line.
Further
- The interpreter, in Python, with a tutorial and the standard library
See also
Also in Golfing
Write your own in Run Convert a program from Jellyfish
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: jellyfish.
Command line
shib run jellyfish -e 'pr5'shib manual jellyfishSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/jellyfish.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language